observablehq / stdlib

The Observable standard library.
https://observablehq.com/@observablehq/standard-library
ISC License
961 stars 83 forks source link

Support opening remote SQLite databases and export #225

Closed john-guerra closed 3 years ago

john-guerra commented 3 years ago

Loading sqlite databases from FileAttachments it is very convenient, but greatly limits the use of the library. It would be nice to easily load remote databases as @mbostock demonstrated in the original sqlite

I'm thinking something like SQLiteDatabaseClient.open that does:

  async open(url) {
     const  db = new SQLite.Database(
        new Uint8Array( await fetch(url).then(res => res.arrayBuffer() ) )
      );
     return new SQLiteDatabaseClient(db);   

Also an export that does something like this._db.export(), and even better a download() that does the whole DOM.download(async () => new Blob([await db._db.export()]), "mydb.db") as I did in my export example

Also, for me it has been very confusing what the SQLite object in a new notebook is. If I'm understanding correctly, it is just sql.js right? It would be nice to have also a method of creating a new Database as in new SQLite.Database() but actually getting a database client object.

BTW I cannot access SQLiteDatabaseClient from a notebook, right?

mbostock commented 3 years ago

Also, for me it has been very confusing what the SQLite object in a new notebook is. If I'm understanding correctly, it is just sql.js right?

Yes, as documented here: https://observablehq.com/@observablehq/recommended-libraries

BTW I cannot access SQLiteDatabaseClient from a notebook, right?

Not currently but I agree it would be nice to expose this functionality.