Member-only story

IndexedDB Manipulation with Dexie — Orders and Joins

John Au-Yeung
3 min readFeb 23, 2021

--

Photo by note thanun on Unsplash

IndexedDB is a way to store data in the browser.

It lets us store larger amounts of data than local storage in an asynchronous way.

Dexie makes working with IndexedDB easier.

In this article, we’ll take a look at how to start working with IndexedDB with Dexie.

Ordering

We can order queries with the between method.

For example, we can write:

(async () => {
const db = new Dexie("friend_database");
try {
await db.version(1).stores({
friends: '++id,[firstName+lastName],age'
});
await db.friends.put({
firstName: "jane",
lastName: 'smith',
age: 39
})
await db.friends.put({
firstName: "jane",
lastName: 'wong',
age: 28
})
const someFriends = await db.friends
.where('[firstName+lastName]')
.between(["jane", ""], ["jane", "\uffff"])
.toArray()
console.log(someFriends)
} catch (error) {
console.log(error);
}
})()

We call between with '' and '\uffff' in the 2nd entry to order the results by lastName .

Also, we can search for items with other methods that act as operators.

--

--

No responses yet