Skip to content

Instantly share code, notes, and snippets.

@dfahlander
Last active December 13, 2020 15:53
Show Gist options
  • Save dfahlander/bef283b1367034d57c7ddac59b1f2185 to your computer and use it in GitHub Desktop.
Save dfahlander/bef283b1367034d57c7ddac59b1f2185 to your computer and use it in GitHub Desktop.
Example of how Dexie's new liveQuery() function works
import Dexie, { liveQuery } from "dexie";
const db = new Dexie('MyDatabase');
db.version(1).stores({
friends: '++id, name, age'
});
const friendsObservable = liveQuery (
() => db.friends
.where('age').above(75)
.toArray()
);
friendsObservable.subscribe({
next: result => console.log("Got result:", result),
error: error => console.error(error)
});
setTimeout(() => db.friends.add({name: "Joe", age: 78}), 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment