MCPcopy Create free account
hub / github.com/Effect-TS/effect / openDatabase

Function openDatabase

packages/platform/browser/src/BrowserPersistence.ts:86–108  ·  view source on GitHub ↗
(database: string)

Source from the content-addressed store, hash-verified

84 )
85
86const openDatabase = (database: string): Effect.Effect<IDBDatabase, Persistence.PersistenceError> =>
87 Effect.gen(function*() {
88 const openRequest = yield* Effect.try({
89 try: () => globalThis.indexedDB.open(database, databaseVersion),
90 catch: (cause) =>
91 new Persistence.PersistenceError({
92 message: "Failed to open backing store database",
93 cause
94 })
95 })
96
97 openRequest.onupgradeneeded = () => {
98 const db = openRequest.result
99 const entries = db.objectStoreNames.contains(entriesStoreName)
100 ? openRequest.transaction?.objectStore(entriesStoreName)
101 : db.createObjectStore(entriesStoreName, { keyPath: ["storeId", "id"] })
102 if (entries && !entries.indexNames.contains(storeIdIndexName)) {
103 entries.createIndex(storeIdIndexName, storeIdIndexName, { unique: false })
104 }
105 }
106
107 return yield* idbRequest("Failed to open backing store database", () => openRequest)
108 })
109
110interface EntryRow {
111 readonly storeId: string

Callers 2

layerBackingIndexedDbFunction · 0.85
layerIndexedDbFunction · 0.85

Calls 1

idbRequestFunction · 0.70

Tested by

no test coverage detected