subframe7536 / kysely-sqlite-tools

SQLite tools for Kysely, include auto serialize plugin, sqlite wasm / sqlite worker / Tauri sqlite plugin / bun:sqlite dialects
https://subframe7536.github.io/kysely-sqlite-tools/
MIT License
54 stars 4 forks source link

Data is not persisted when using WaSqliteWorkerDialect #5

Closed Feroks closed 11 months ago

Feroks commented 11 months ago

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?

subframe7536 commented 11 months ago
  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 11 months ago
  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.
subframe7536 commented 11 months ago

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