UNPKG

@idxdb/promised

Version:

@idxdb/promised wraps the IndexedDB API. It allows you to easily store and retrieve data in an indexed db database using async/await syntax, making it easier to integrate with your existing codebase.

26 lines (25 loc) 784 B
import { ObjectStore } from '../component/object-store.js'; import { Transaction } from '../component/transaction.js'; export class Database { ctx; constructor(ctx) { this.ctx = ctx; } close() { this.ctx.db.close(); } createObjectStore(name, options) { const objectStore = this.ctx.db.createObjectStore(name, options); return new ObjectStore({ objectStore }); } deleteObjectStore(name) { return this.ctx.db.deleteObjectStore(name); } transaction(storeNames, mode, options) { const transaction = this.ctx.db.transaction(storeNames, mode, options); return new Transaction({ transaction }); } get objectStoreNames() { return Array.from(this.ctx.db.objectStoreNames); } }