No real changes, just renames
This commit is contained in:
parent
4704b2a0e4
commit
2e8292a65f
10 changed files with 31 additions and 35 deletions
32
web/src/app/db.js
Normal file
32
web/src/app/db.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
import Dexie from "dexie";
|
||||
import session from "./Session";
|
||||
import sessionReplica from "./SessionReplica";
|
||||
|
||||
// Uses Dexie.js
|
||||
// https://dexie.org/docs/API-Reference#quick-reference
|
||||
//
|
||||
// Notes:
|
||||
// - As per docs, we only declare the indexable columns, not all columns
|
||||
|
||||
const createDatabase = (username) => {
|
||||
const dbName = username ? `ntfy-${username}` : "ntfy"; // IndexedDB database is based on the logged-in user
|
||||
const db = new Dexie(dbName);
|
||||
|
||||
db.version(1).stores({
|
||||
subscriptions: "&id,baseUrl,[baseUrl+mutedUntil]",
|
||||
notifications: "&id,subscriptionId,time,new,[subscriptionId+new]", // compound key for query performance
|
||||
users: "&baseUrl,username",
|
||||
prefs: "&key",
|
||||
});
|
||||
|
||||
return db;
|
||||
};
|
||||
|
||||
export const dbAsync = async () => {
|
||||
const username = await sessionReplica.username();
|
||||
return createDatabase(username);
|
||||
};
|
||||
|
||||
export const db = () => createDatabase(session.username());
|
||||
|
||||
export default db;
|
Loading…
Add table
Add a link
Reference in a new issue