Last active
March 3, 2020 18:46
-
-
Save rmehner/ebfa37db2b27e3f0431c3dc97d385f3b to your computer and use it in GitHub Desktop.
Using unique compound indizes with Dexie.js
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
const db = new Dexie('friends') | |
db.version(1).stores({ | |
friends: '++id,&[name+age]', | |
}) | |
async function main() { | |
await db.friends.add({ name: 'Robin', age: 1337 }) | |
// this will fail with: | |
// ConstraintError: A mutation operation in the transaction failed because a constraint was not satisfied. | |
await db.friends.add({ name: 'Robin', age: 1337 }) | |
// query like this: | |
const allMyFriendsAreDead = await db.friends.where({ | |
name: 'Robin', | |
age: 1337, | |
}) | |
console.log(allMyFriendsAreDead) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment