Skip to content
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

Allow importing DuckDB databases #19

Open
tobilg opened this issue Aug 27, 2024 · 0 comments
Open

Allow importing DuckDB databases #19

tobilg opened this issue Aug 27, 2024 · 0 comments

Comments

@tobilg
Copy link
Contributor

tobilg commented Aug 27, 2024

It'd be great to be able to import (attach) DuckDB database files as well, similar to CSV, Parquet and Arrow files.

The code I'm currently using is basically this:

const loadDatabase = async (db: AsyncDuckDB, acceptedFile: File) => {
    try {
      const fileName = acceptedFile.name.replace(".duckdb", "");
      // Connect to the database
      const cid = await db.connectInternal();
      // Register the file
      await db.registerFileBuffer(fileName, new Uint8Array(await acceptedFile.arrayBuffer()));
      // Attach the database
      await db.runQuery(cid, `ATTACH '${fileName}' (READ_ONLY)`);
      // Disconnect from the database
      await db.disconnect(cid);
    } catch (err: any) {
      console.log(err);
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant