Last active
December 13, 2020 15:53
-
-
Save dfahlander/bef283b1367034d57c7ddac59b1f2185 to your computer and use it in GitHub Desktop.
Example of how Dexie's new liveQuery() function works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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