MCPcopy
hub / github.com/codedogQBY/ReadAny / initDatabase

Function initDatabase

packages/core/src/db/db-core.ts:326–740  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

324
325/** Initialize the database, creating tables if needed */
326export async function initDatabase(): Promise<void> {
327 if (dbInitialized) return;
328 if (dbInitPromise) return dbInitPromise;
329
330 dbInitPromise = (async () => {
331 await runSerializedDbTask(async () => {
332 if (dbInitialized) return;
333
334 const database = await getDB();
335
336 // Create tables
337 await database.execute(`
338 CREATE TABLE IF NOT EXISTS books (
339 id TEXT PRIMARY KEY,
340 file_path TEXT NOT NULL,
341 format TEXT NOT NULL DEFAULT 'epub',
342 title TEXT NOT NULL DEFAULT '',
343 author TEXT NOT NULL DEFAULT '',
344 publisher TEXT,
345 language TEXT,
346 isbn TEXT,
347 description TEXT,
348 cover_url TEXT,
349 publish_date TEXT,
350 rating REAL,
351 reviews TEXT,
352 subjects TEXT,
353 total_pages INTEGER DEFAULT 0,
354 total_chapters INTEGER DEFAULT 0,
355 group_id TEXT,
356 added_at INTEGER NOT NULL,
357 last_opened_at INTEGER,
358 deleted_at INTEGER,
359 progress REAL DEFAULT 0,
360 current_cfi TEXT,
361 is_vectorized INTEGER DEFAULT 0,
362 vectorize_progress REAL DEFAULT 0,
363 tags TEXT DEFAULT '[]'
364 )
365 `);
366
367 await database.execute(`
368 CREATE TABLE IF NOT EXISTS book_groups (
369 id TEXT PRIMARY KEY,
370 name TEXT NOT NULL,
371 sort_order INTEGER DEFAULT 0,
372 created_at INTEGER NOT NULL,
373 updated_at INTEGER NOT NULL DEFAULT 0,
374 sync_version INTEGER DEFAULT 0,
375 last_modified_by TEXT
376 )
377 `);
378
379 await database.execute(`
380 CREATE TABLE IF NOT EXISTS highlights (
381 id TEXT PRIMARY KEY,
382 book_id TEXT NOT NULL,
383 cfi TEXT NOT NULL,

Callers 4

reopenDatabaseMethod · 0.90
reopenDatabaseMethod · 0.90
bootstrapFunction · 0.85

Calls 6

runSerializedDbTaskFunction · 0.90
getPlatformServiceFunction · 0.90
getDBFunction · 0.85
cleanupOrphanedSyncRowsFunction · 0.85
initLocalDatabaseFunction · 0.85
executeMethod · 0.65

Tested by

no test coverage detected