Sqlite - Inserted rows do not get pushed from cache to the disk

I am using drizzle-sqlite in a svlete project. The project has db.ts that creates a new sqlite db on a local file and exports db like so: export const db: BetterSQLite3Database<typeof schema> = drizzle(sqlite, { // to use query builders like findMany() schema, }); where schema is in schema.ts (currently reduced to a single table with three columns of type text. A test page has a form with a single button which on click inserts a bunch of records in the db db.insert(mytable).values({....}) and another form with a single button which displays the records for the db. db.query.mytable.findMany() After insert, my query returns the rows inserted bu drizzle studio does not show them and after quitting and relaunching the app, the rows are not in the db. The sqlite db file also shows timestamp of before the insert operations. Seems that records were in the cache after the insert but never pushed to the disk. Do I have to do anything special to make data persistent? Could it be anything in the config that would make data ephemeral? Thanks for help.
2 Replies
tacomanator
tacomanator9mo ago
what does the line above that where you define sqlite look like? did you try turning the logger on?
const db = drizzle(sqlite, { schema, logger: true });
const db = drizzle(sqlite, { schema, logger: true });
what happens if you put the insert query and select query all in the same file directly below where your exporting db the variable?
hemant1770
hemant1770OP9mo ago
@tacomanator Found it. It turned out to be what I would definitely consider a bug in better-sqlite3. new Database(myDbFilePath) was getting undefined which it really should throw error for but did not. Just happily created data in memory without a disk file backing it!!!! Thanks for your help.
Want results from more Discord servers?
Add your server