subframe7536/kysely-sqlite-tools

Data is not persisted when using WaSqliteWorkerDialect

Feroks opened this issue · 3 comments

Feroks commented

I have SvelteKit SPA application and use following code to initialize Kyseley:

import { Kysely } from 'kysely';
import { WaSqliteWorkerDialect } from 'kysely-wasqlite-worker'
import type { Database } from './types';

const dialect = new WaSqliteWorkerDialect({
	fileName: 'test',
	preferOPFS: true
});

return new KyselyEx<Database>({ dialect });

If i initialize it again or reload the page all my data and tables are gone. I have tried to set preferOPFS to false, but it does not help.
I guess i am doing something wrong. Do you have any suggestions?

  1. check if your browser support OPFS
  2. check if the worker and wasm is loaded, you can see examples in playground
  3. if preferOPFS: false, go to devtools > Application > IndexedDB and check if the database exists
  4. if preferOPFS: true, use OPFS explorer extension and check if the directory exists

Also, there will be some improvements and bug fix if I have some times to release

Feroks commented
  1. I am using latest Chrome version (on PC).
  2. I can see worker in Developer tools. HTTP request that loads WASM is succesfull isIdbSupported, isModuleWorkerSupport and isOpfsSupported all return true. I can run queries on the database, but the moment page is refreshed, data is gone.
  3. Database exists, but there is no data event after performing insert.
  4. Directory exists. It has 6 files with random text as name.

You're right. I tested it locally and there indeed is a data loss issue.

You can use v0.5.1 for now. Maybe it is caused by the upstream lib and need some times to fix it