duckdb-wasm import as plain js module #1632
Replies: 3 comments 4 replies
-
Hi! Yes, it's currently possible with a bundler, but we should make it available out of the box, and add a simple example. Thanks for raising this, moved as a issue here:#1633 |
Beta Was this translation helpful? Give feedback.
-
i kind of figured that out: /* https://www.jsdelivr.com/package/npm/@duckdb/duckdb-wasm */
<script type="module">
import * as duckdbduckdbWasm from "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.28.1-dev106.0/+esm";
window.duckdbduckdbWasm = duckdbduckdbWasm;
</script> const duckdb = window.duckdbduckdbWasm as any;
export const getDb = async () => {
// @ts-ignore
if (window._db) return window._db;
const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();
// Select a bundle based on browser checks
const bundle = await duckdb.selectBundle(JSDELIVR_BUNDLES);
const worker_url = URL.createObjectURL(
new Blob([`importScripts("${bundle.mainWorker}");`], {
type: "text/javascript",
})
);
// Instantiate the asynchronus version of DuckDB-wasm
const worker = new Worker(worker_url);
// const logger = null //new duckdb.ConsoleLogger();
const logger = new duckdb.ConsoleLogger();
const db = new duckdb.AsyncDuckDB(logger, worker);
await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
URL.revokeObjectURL(worker_url);
window._db = db
return db;
};
let me know if this is a proper way to do it |
Beta Was this translation helpful? Give feedback.
-
btw is there any documentation related to the wasm API, e.g. the arguments accepted by the "query" function, what is the meaning of the "send" function an so on ... the only piece of doc i could find is this, but it is not the full API: https://duckdb.org/docs/api/wasm/query also: is there any nicer way to get results for queries such as "select 42;" instead of having to use .toArray() ? |
Beta Was this translation helpful? Give feedback.
-
would it be possible to use duckdb in a plain index.html page without help of any bundler ? if so, is there any example out there ?
Beta Was this translation helpful? Give feedback.
All reactions