MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / open

Method open

packages/node-runtime/src/database-manager.ts:75–94  ·  view source on GitHub ↗

* Open a session DB (read-only by default, cached).

(sessionId: string, options?: { readonly?: boolean })

Source from the content-addressed store, hash-verified

73 * Open a session DB (read-only by default, cached).
74 */
75 open(sessionId: string, options?: { readonly?: boolean }): DatabaseAdapter | null {
76 this.assertCompatible()
77
78 if (this.cache.has(sessionId)) {
79 return this.cache.get(sessionId)!
80 }
81
82 const dbPath = this.getDbPath(sessionId)
83 if (!fs.existsSync(dbPath)) return null
84
85 this.migrateIfNeeded(dbPath)
86 this.assertCompatible()
87
88 const adapter = openBetterSqliteDatabase(dbPath, {
89 readonly: options?.readonly ?? true,
90 nativeBinding: this.nativeBinding,
91 })
92 this.cache.set(sessionId, adapter)
93 return adapter
94 }
95
96 private migrateIfNeeded(dbPath: string): void {
97 const readonlyAdapter = openBetterSqliteDatabase(dbPath, {

Callers 1

listSessionIdsMethod · 0.95

Calls 6

assertCompatibleMethod · 0.95
getDbPathMethod · 0.95
migrateIfNeededMethod · 0.95
openBetterSqliteDatabaseFunction · 0.90
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected