Collection

The WireBootstrap IndexedDB Connector's service provider can be used as a collection into IndexedDB database stores. The service provider contains methods for maintaining stores using a key into the collection.

The service provider class constructor takes the key name as the first parameter and optionally an array of data to set into IndexedDB to be maintained using the collection.

The following example creates a new instance of the service provider directly. It specifies the data to be an array of fruits with the name field being the key into the collection.

const fruits = [
  { name: "grapes", color: "green"},
  { name: "bananas", color: "yellow"},
  { name: "apples", color: "red"},
];

const col = new wire.indexedDb("name", fruits);

GetAll

To retrieve all objects from the store created above in IndexedDB, use the getAll method.

...
const fruits = await col.getAll();

Get

To pull a single object from the IndexedDB store, use the get method specifying the value for the key into the collection.

...
const fruit = await col.get("grapes");

Put

To add an object to the IndexedDB store, use the put method with the object.

...
const fruit = { name: "oranges", color: "orange"};
await col.put(fruit);

Delete

To remove an object from the IndexedDB store, use the delete method specifying the key value for the object to be removed.

...
await col.delete("bananas");

Last updated