-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lock error using existing database #20
Comments
I am so sorry for the delay here! Work got super busy right after I launched this because I had put off some stuff for this, but I'll be going through the issues soon. Thanks so much! |
No worries, it's FOSS after all. Thanks again for making this library. Being able to import/export an existing SQLite database would basically make irrelevant the one thing PouchDB still has going for it (replicated sync), and I'd love to get out of PouchDB hell... |
@dpmccabe , In case you're still looking for a solution, I've made a slight change to 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');
// host an example file somewhere with permissive CORS settings
const data = await fetch("https://example.com/chinook.db").then(res => res.arrayBuffer());
const db = new SQL.Database(new Uint8Array(data), {filename: '/sql/chinook.db'});
return db;
}
async function runQueries() {
let db = await init();
const stmt = db.prepare("SELECT Name FROM artists;");
stmt.step(); // Execute the statement
console.log(stmt.getAsObject());
}
runQueries(); |
Thanks for the fix. I was able to get that code to work with
Maybe this is just a problem with the distributed wasm files on npm? |
From which package you're using sql-wasm.wasm? |
Hmm, never mind. When I copied a fresh copy of |
@urdeveloper Are you planning on submitting your change in a PR? I find your changes very useful. |
@awmuncy, I'd love to but I'm pretty sure, it's not going to go anywhere. jlongster himself also made a PR on the upstream sql.js and which never been merged. Th good thing is you have your own fork because both absurd-sql and sql.js authors were very generous with the licensing. Cheers! |
Is there a way to initialize a database using an existing SQLite file? For instance, here's what it might look like if I combine your example repo with a sql.js example to load an existing database from a URL:
This is the error that gets generated:
Maybe it makes sense that it doesn't work. Your version of
SQL.Database
doesn't let you specify a filename if you give it a data array instead of a filename. There might be other limitations preventing this pattern from working, but I'm not sure.This might be a trivial fix to your sql.js fork, but I'm unable to try it out since I've had all sorts of problems getting local versions of absurd-sql and sql.js to work with the example project.
The text was updated successfully, but these errors were encountered: