Barebones example of querying with duckdb-wasm using Vite and just the browser (no front-end framework). No dataset file is loaded; the data is created using the generate_series function.
- Install the dependencies using
npm i
- Run the example using
npm run preview
- (Optional) If forking, use
npm run dev
and go from there!
Everything runs from the main.js script which roughly does the following:
- Import: duckdb-wasm and all its bundle alternatives
- Pick bundle: Choose based on the browser in-use
- Instantiate: Start duckdb and create a connection
- Query: Select from the "database" (generate_series) using a basic query or a prepared statement
- Close: The connection, database, and worker.
Notes:
- For ease of use when showing the results, JSON copies of the query results are printed to the console. Consequently...
- ...this example is not acquainted with proper usage of the Apache Arrow objects like Table.
- Making JSON copies of large query results for console.log may not be advisable