2022-03-02 15:23:12 +13:00
|
|
|
import Dexie from 'dexie';
|
2022-12-03 09:37:48 +13:00
|
|
|
import session from "./Session";
|
2022-03-02 15:23:12 +13:00
|
|
|
|
|
|
|
// Uses Dexie.js
|
|
|
|
// https://dexie.org/docs/API-Reference#quick-reference
|
|
|
|
//
|
|
|
|
// Notes:
|
|
|
|
// - As per docs, we only declare the indexable columns, not all columns
|
|
|
|
|
2023-01-19 09:50:06 +13:00
|
|
|
// The IndexedDB database name is based on the logged-in user
|
2022-12-03 09:37:48 +13:00
|
|
|
const dbName = (session.username()) ? `ntfy-${session.username()}` : "ntfy";
|
|
|
|
const db = new Dexie(dbName);
|
2022-03-02 15:23:12 +13:00
|
|
|
|
2022-05-08 11:16:08 +12:00
|
|
|
db.version(1).stores({
|
2022-03-03 10:16:30 +13:00
|
|
|
subscriptions: '&id,baseUrl',
|
2022-05-08 11:16:08 +12:00
|
|
|
notifications: '&id,subscriptionId,time,new,[subscriptionId+new]', // compound key for query performance
|
2022-03-02 16:01:51 +13:00
|
|
|
users: '&baseUrl,username',
|
|
|
|
prefs: '&key'
|
2022-03-02 15:23:12 +13:00
|
|
|
});
|
|
|
|
|
|
|
|
export default db;
|