Basically, if you have objectStores 'students' with an index 'name' and 'schools' with an index 'city', and you query the 'name' index on 'students' with no range specified (or WITH a range - it doesnt matter), you will get a cursor that iterates a mix of student names and cities. Each onsuccess callback from the cursor will have a key that sometimes is a student name and sometimes a city. The value though is always a student and some students are shown multiple times - one time with the name key and another time with a city key.
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
// This module shall be imported from BrowserWindow's main modules. The node main thread should instead import "workaround-ipc". | |
// NOTE: This gist shall not be used if Electron solves issue https://github.com/electron/electron/issues/37417 | |
import Dexie from "dexie"; | |
import { ipcRenderer } from "electron"; | |
if ("unref" in BroadcastChannel.prototype) { | |
// Node's BroadcastChannel has the `unref()` method. | |
// Seems we got the Node- and not the DOM version of BroadcastChannel. | |
// Only activate this workaround when we have the Node-version of BroadcastChannel |
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
// This module shall be imported from the main node module in electron. | |
// The BrowserWindows shall instead import 'workaround-renderer.ts' | |
// NOTE: This gist shall NOT be used in Electron versions where https://github.com/electron/electron/issues/37417 is resolved | |
import { ipcMain } from "electron"; | |
import { BrowserWindow } from "electron"; | |
if (typeof BroadcastChannel !== "undefined") { | |
// We're on electron version 23 with BroadcastChannel support in node | |
ipcMain.on("dexie-storagemutated", (event, json) => { |
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
// On any web page that stores things in IndexedDB, | |
// open devtools and in the console, write the following: | |
script1 = document.createElement('script'); | |
script1.src = 'https://unpkg.com/[email protected]'; | |
document.body.appendChild(script1); | |
script2 = document.createElement('script'); | |
script2.src = 'https://unpkg.com/[email protected]'; | |
document.body.appendChild(script2); |
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
function FriendsComponent({minAge = 75}) { | |
const friends = useLiveQuery( | |
() => db.friends | |
.where('age').aboveOrEqual(minAge) | |
.toArray() | |
); | |
return friends && <ul>{ | |
friends.map(friend => | |
<li key={friend.id}> |
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) |
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
<html> | |
<script src="https://unpkg.com/dexie/dist/dexie.js"></script> | |
<script> | |
const log = txt => console.log(txt);//document.writeln(`${txt}<br/>`); | |
log (`Hello world!`); | |
let db = new Dexie ('db'); | |
db.version(1).stores({ | |
friends: '++id,name,age' | |
}); |
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
<html> | |
<script> | |
const log = txt => document.writeln(`${txt}<br/>`); | |
log("Deleting db2"); | |
indexedDB.deleteDatabase("db2").onsuccess = ()=> { | |
log("db2 deleted"); | |
let req = indexedDB.open("db2", 1); | |
req.onupgradeneeded = e => { | |
log ("Creating db2"); | |
let db = req.transaction.db; |
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
<html> | |
<script> | |
document.writeln("Hello world!"); | |
</script> | |
</html> |
NewerOlder