Data Source

IndexedDB can be used with a traditional WireBootstrap data source to query data in stores. It can also be used as a collection into the IndexedDB object repository.

The following example illustrates the steps needed to query data inside an IndexedDB store using a data source.

Data Source

First, create the data source that uses the IndexedDB Connector's service provider. If the store does not yet exist, a new store can be created using the provider's data source configuration.

// create an array of objects
const fruits = [
 { name: "grapes", color: "green"},
 { name: "bananas", color: "yellow"},
 { name: "apples", color: "red"},
];

// create an IndexedDB store and add the array of objects to the it
const source = new wire.data.DataSource("indexed-db", {
  Provider: {
     stores: [
          { name: "My Store", data: fruits }
      ]}
});

Query

Next, create a WireBootstrap select query and then execute the query against IndexedDB. The query will return a WireBootstrap DataTable. In the query, the store name is specified in the from clause.

// create the query
const query = wire.data.select()
    .from("My Store")
    .where().eq("name", "apples");

// run it against IndexedDB
const table = await source.execAsync(query);

Last updated