* Initialize the database (lazy loading)
()
| 19 | * Initialize the database (lazy loading) |
| 20 | */ |
| 21 | private async initDb(): Promise<void> { |
| 22 | if (this.db) return; |
| 23 | |
| 24 | // Check if we're in a browser environment |
| 25 | if (typeof window !== 'undefined') { |
| 26 | throw new Error('SQLite is not supported in browser environments. Please reduce data size or use in-memory processing.'); |
| 27 | } |
| 28 | |
| 29 | try { |
| 30 | // Dynamic import for Node.js-only module |
| 31 | const Database = (await import('better-sqlite3')).default; |
| 32 | this.db = new Database(this.dbPath); |
| 33 | } catch (error) { |
| 34 | throw new Error( |
| 35 | `Failed to load better-sqlite3. This module is only available in Node.js environments: ${error instanceof Error ? error.message : String(error)}` |
| 36 | ); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Load data into SQLite table |