Member-only story
IndexedDB Manipulation with Dexie — Complex Queries
3 min readFeb 23, 2021
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.
Query and Modify Data
We can query for and modify data at the same time.
For example, we can write:
(async () => {
const db = new Dexie("friend_database");
try {
await db.version(1).stores({
friends: 'name,age'
});
await db.friends.put({
name: "mary",
age: 68
})
await db.friends.put({
name: "jane",
age: 28
})
await db.friends
.where('age')
.inAnyRange([
[0, 18],
[65, Infinity]
])
.modify({
discount: 0.5
});
} catch (error) {
console.log(error);
}
})()
We get all the entries of the friends
table with age
between 0 to 18 or 65 and up.
Then we call modify
to change the discount
field to 0.5.