DuckDB In Vanilla JS With Observable's DuckDB Library
If all worked as planned, you'll see a scrolling table at the end of page. Said table was made from a query against four remote parquet files. This time, we're using Observable's helper library.
See the pure vanilla example for more commentary. We're just showcasing the differences.
Now, the remaining differences lie in how to instantiate the DuckDB instance and wire up the tables:
- DuckDB is part of the Observable standard
Library
so we need to get to it. - Note the need for
()
, here, as it's a class - The Observable wrapper normalizes the DuckDB wrapper to the
DatabaseClient
standard.
The last differences in in how we execute the query.
- The
DatabaseClient
spec defines asql
tagged template literal function which just shortens the typing by a few keystrokes (but it does feel cooler when you use it).
The remaining code is the same as the vanilla example.
And, here is the result!
You can view this example standalone, as well.
NOTE: since I'm still learning Nue, you may need to hard refresh this page to see the table, as Nue does fancy rendering tricks that may not trigger the load. The parquet files may take multiple seconds to load, too.