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

Function openDatabase

apps/desktop/main/worker/core/dbCore.ts:34–51  ·  view source on GitHub ↗
(sessionId: string)

Source from the content-addressed store, hash-verified

32 * 打开数据库(带缓存)
33 */
34export function openDatabase(sessionId: string): Database.Database | null {
35 // 检查缓存
36 if (dbCache.has(sessionId)) {
37 return dbCache.get(sessionId)!
38 }
39
40 const dbPath = getDbPath(sessionId)
41 if (!fs.existsSync(dbPath)) {
42 return null
43 }
44
45 const db = new Database(dbPath, { readonly: true })
46 db.pragma('journal_mode = WAL')
47
48 // 缓存连接
49 dbCache.set(sessionId, db)
50 return db
51}
52
53/**
54 * 关闭指定会话的数据库连接

Callers 6

getSessionFunction · 0.90
getChatOverviewFunction · 0.90
hasFtsIndexFunction · 0.90
searchByFtsFunction · 0.90
createSyncExecutorFunction · 0.90
openDatabaseAdapterFunction · 0.70

Calls 4

setMethod · 0.80
getDbPathFunction · 0.70
getMethod · 0.65
pragmaMethod · 0.65

Tested by

no test coverage detected