Replies: 2 comments 1 reply
-
Using the new version of sql.js mentioned in that issue, a simple syncing procedure might look something like this: import initSqlJs from '@urdeveloper/sql.js';
import { SQLiteFS } from 'absurd-sql';
import IndexedDBBackend from 'absurd-sql/dist/indexeddb-backend';
async function init() {
let SQL = await initSqlJs({ locateFile: (file) => file });
let sqlFS = new SQLiteFS(SQL.FS, new IndexedDBBackend());
SQL.register_for_idb(sqlFS);
SQL.FS.mkdir('/sql');
SQL.FS.mount(sqlFS, {}, '/sql');
const data = await fetch(
'https://example.com/chinook.db'
).then((res) => res.arrayBuffer());
return new SQL.Database(new Uint8Array(data), {
filename: '/sql/chinook.db'
});
}
// init db from remote URL
const db = await init();
// sync back
const data = db.export();
const blob = new Blob([data], { type: 'application/octet-stream' });
const formData = new FormData();
formData.append('db', blob);
const res = await fetch('http://example.com/api/update-db', { method: 'POST', body: formData });
console.log('res:', res); You'll need a back-end API that has the ability to update the remote file. A more complex but less network-intensive method would be to maintain a log of all SQL statements performed locally so that they could be replayed on the remote DB, but then you have to worry about syncing those statements back to other clients, too. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Similar projects
https://github.com/mWater/minimongo
https://dexie.org/docs/Syncable/Dexie.Syncable.js.html
Beta Was this translation helpful? Give feedback.
All reactions