You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// no ?module needed, it's the main export in unpkgimport{init}from"//unpkg.com/sqlite-worker";// `dist` option resolved automatically via import.meta.urlinit({name: "my-db1",update(uInt8Array){console.log("updated",uInt8Array);},}).then(async({ all, get, query, raw, transaction })=>{consttable=raw`todos`;awaitquery`CREATE TABLE IF NOT EXISTS ${table} (id INTEGER PRIMARY KEY, value TEXT)`;const{ total }=awaitget`SELECT COUNT(id) as total FROM ${table}`;if(total<10){console.log("Inserting some value");awaitquery`INSERT INTO ${table} (value) VALUES (${"a"})`;awaitquery`INSERT INTO ${table} (value) VALUES (${"b"})`;awaitquery`INSERT INTO ${table} (value) VALUES (${"c"})`;}constinsert=transaction();for(leti=0;i<10;i++)insert`INSERT INTO todos (value) VALUES (${"Ipsum "+i})`;awaitinsert.commit();console.log(awaitall`SELECT * FROM ${table}`);});
Can we export a defer update function, save function to manual trigger save ?
I wonder if exporting explicitly that save instead would be a better option ... and btw, these days I suggest https://github.com/WebReflection/sql.js instead, where you can add sqlite-tag or any other extra logic you need. It works in both main and workers too.
Oh I see, but this repo like a heavy lifting about "worker messaging", it's like a shortest way to kick start and use sqlite wasm in worker. So I think this repo is still good as its purpose.
Yah, exporting save is good enough option :) Until that, I think have to use the trick
probably, but that's why I think the current "magic handler on changes" is too magic ... having a whole scan/parser for the syntax feels overkill, not having it might always allow hacks or fail in some occasion ... explicit is better than implicit as users writing queries surely know when they want these to be updated, me delaying an interval after guessing some action feels ... meh ...
Before searching your repo, I think I will use sql.js export with a timer for checking checksum the Uint8Array then saving to storage. Even checksum crc32 is good for detecting changes. Just an idea :)
thing is ... timers get easily discarded when you unload a page while IndexedDB operations that have been already triggered might get some time to complete their operation before the browser fully discard that page ... so timers might not a robust solution, but then again I am not sure there are guarantees with IDB transactions neither, but I expect that to be the case.
Activity
WebReflection commentedon Nov 20, 2024
I wonder if exporting explicitly that
saveinstead would be a better option ... and btw, these days I suggest https://github.com/WebReflection/sql.js instead, where you can add sqlite-tag or any other extra logic you need. It works in both main and workers too.khanhicetea commentedon Nov 20, 2024
Oh I see, but this repo like a heavy lifting about "worker messaging", it's like a shortest way to kick start and use sqlite wasm in worker. So I think this repo is still good as its purpose.
Yah, exporting
saveis good enough option :) Until that, I think have to use the trickThanks
WebReflection commentedon Nov 20, 2024
probably, but that's why I think the current "magic handler on changes" is too magic ... having a whole scan/parser for the syntax feels overkill, not having it might always allow hacks or fail in some occasion ... explicit is better than implicit as users writing queries surely know when they want these to be updated, me delaying an interval after guessing some action feels ... meh ...
khanhicetea commentedon Nov 21, 2024
Before searching your repo, I think I will use sql.js export with a timer for checking checksum the Uint8Array then saving to storage. Even checksum crc32 is good for detecting changes. Just an idea :)
WebReflection commentedon Nov 21, 2024
thing is ... timers get easily discarded when you unload a page while IndexedDB operations that have been already triggered might get some time to complete their operation before the browser fully discard that page ... so timers might not a robust solution, but then again I am not sure there are guarantees with IDB transactions neither, but I expect that to be the case.