vector-im-hydrogen-web/src/matrix/storage/idb/create.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-02-06 23:04:39 +01:00
import Storage from "./storage.js";
import { openDatabase } from "./utils.js";
2019-02-05 00:21:50 +01:00
export default async function createIdbStorage(databaseName) {
2019-02-07 00:19:14 +01:00
const db = await openDatabase(databaseName, createStores, 1);
2019-02-05 00:21:50 +01:00
return new Storage(db);
}
function createStores(db) {
2019-02-07 01:20:27 +01:00
db.createObjectStore("session", {keyPath: "key"});
// any way to make keys unique here? (just use put?)
db.createObjectStore("roomSummary", {keyPath: "roomId"});
2019-04-18 20:19:43 +02:00
db.createObjectStore("timelineFragments", {keyPath: ["roomId", "id"]});
// needs roomId separate because it might hold a gap and no event
2019-04-18 20:19:43 +02:00
const timelineEvents = db.createObjectStore("timelineEvents", {keyPath: ["event.room_id", "fragmentId", "sortKey"]});
timelineEvents.createIndex("byEventId", [
"event.room_id",
2019-02-10 21:25:29 +01:00
"event.event_id"
], {unique: true});
db.createObjectStore("roomState", {keyPath: [
"roomId",
"event.type",
"event.state_key"
]});
// const roomMembers = db.createObjectStore("roomMembers", {keyPath: [
// "event.room_id",
// "event.content.membership",
// "event.state_key"
// ]});
// roomMembers.createIndex("byName", ["room_id", "content.name"]);
2019-04-18 20:19:43 +02:00
}