mirror of
https://github.com/zadam/trilium.git
synced 2026-01-12 09:34:26 +01:00
feat(client/lightweight): import demo database
This commit is contained in:
parent
405db7cedb
commit
7832f20c89
6538
apps/client/src/lightweight/db.sql
Normal file
6538
apps/client/src/lightweight/db.sql
Normal file
File diff suppressed because one or more lines are too long
@ -1,6 +1,7 @@
|
||||
import type { DatabaseProvider, RunResult, Statement, Transaction } from "@triliumnext/core";
|
||||
import sqlite3InitModule from "@sqlite.org/sqlite-wasm";
|
||||
import type { BindableValue } from "@sqlite.org/sqlite-wasm";
|
||||
import demoDbSql from "./db.sql?raw";
|
||||
|
||||
// Type definitions for SQLite WASM (the library doesn't export these directly)
|
||||
type Sqlite3Module = Awaited<ReturnType<typeof sqlite3InitModule>>;
|
||||
@ -204,8 +205,17 @@ export default class BrowserSqlProvider implements DatabaseProvider {
|
||||
|
||||
loadFromMemory(): void {
|
||||
this.ensureSqlite3();
|
||||
console.log("[BrowserSqlProvider] Loading demo database...");
|
||||
const startTime = performance.now();
|
||||
|
||||
this.db = new this.sqlite3!.oo1.DB(":memory:", "c");
|
||||
this.db.exec("PRAGMA journal_mode = WAL");
|
||||
|
||||
// Load the demo database by default
|
||||
this.db.exec(demoDbSql);
|
||||
|
||||
const loadTime = performance.now() - startTime;
|
||||
console.log(`[BrowserSqlProvider] Demo database loaded in ${loadTime.toFixed(2)}ms`);
|
||||
}
|
||||
|
||||
loadFromBuffer(buffer: Uint8Array): void {
|
||||
|
||||
@ -3,8 +3,8 @@
|
||||
// import { createCoreServer } from "@trilium/core"; (bundled)
|
||||
|
||||
import BrowserExecutionContext from './lightweight/cls_provider';
|
||||
import BrowserSqlProvider from './lightweight/sql_provider';
|
||||
import BrowserCryptoProvider from './lightweight/crypto_provider';
|
||||
import BrowserSqlProvider from './lightweight/sql_provider';
|
||||
|
||||
// Global error handlers - MUST be set up before any async imports
|
||||
self.onerror = (message, source, lineno, colno, error) => {
|
||||
@ -70,19 +70,6 @@ async function initSQLite(): Promise<void> {
|
||||
// Open an in-memory database
|
||||
sqlProvider.loadFromMemory();
|
||||
console.log("[Worker] Database opened via provider");
|
||||
|
||||
// Create a simple test table
|
||||
sqlProvider.exec(`
|
||||
CREATE TABLE IF NOT EXISTS options (
|
||||
name TEXT PRIMARY KEY,
|
||||
value TEXT
|
||||
);
|
||||
INSERT INTO options (name, value) VALUES
|
||||
('theme', 'dark'),
|
||||
('layoutOrientation', 'vertical'),
|
||||
('headingStyle', 'default');
|
||||
`);
|
||||
console.log("[Worker] Test table created and populated");
|
||||
} catch (error) {
|
||||
sqlInitError = String(error);
|
||||
console.error("[Worker] SQLite initialization failed:", error);
|
||||
@ -120,7 +107,7 @@ async function loadCoreModule() {
|
||||
// No-op for now
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
console.log("[Worker] @triliumnext/core loaded successfully");
|
||||
return coreModule;
|
||||
} catch (e) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user