buddyGenAI Database Info
This is meant to explain how BGAI uses and handles a database across its versions.
Electron version
mainbranchCode found at
/migrations/*,/electron/modules/db.ts,/src/lib/sql.tsand/src/lib/api/*.
- uses SQLite via better-sqlite3
- Schema @
/migrations/*.sql - IPC methods are exposed (in
/electron/modules/db.ts) and used (in/src/composables/useElectron.ts) to run SQL (parameterized) queries constructed by the renderer process. - Helper methods in
/src/lib/sql.tsare used in/src/lib/api/*files to avoid writing statements directly.
Single Page App version
spa-versionbranchCode found at
/src/lib/db/schema.ts,/src/lib/sql.tsand/src/lib/api/*.
- uses IndexedDB via Dexie.js
- Schema @
/src/lib/db/schema.ts - DB is queried in
/src/lib/api/*files, with rewritten helper methods in/src/lib/sql.tsto construct equivalent Dexie statements/queries from the same arguments. - The
useElectronmethods are modified to query Dexie directly and return the results.
Eventual Goal
After some thinking, I think what I want to do overall is use Dexie for all versions and simply have different behavior for different versions:
- SPA remains the same.
- Electron version would use the same code as the SPA, and would save/load to file(s) when data changes and on app start.
- Server version could maintain a single (or multiple) set of DB files which would be used to hydrate a client's IndexedDB on load. I'm thinking that there would be controls for syncing to the server, essentially allowing you to use the app in SPA mode despite connecting to a Server instance.
