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. Let's see how it came together.
NOTE: Any bulleted line number references refer to the code block above the numbered bullets.
We'll start with…
This gets of the Tabulator "midnight" theme for the table. There are other ones we can use, or we can make our own.
This pull in luxon so we can have Tabulator let us sort the day column in the table.
We need a place to render the table, so we set up a <div> for that:
We'll target this <div> by the tblid attribute value. We use the tabulator class so it formats nicely.
Now, everything else is in a <script type="module"> tag.
This imports DuckDB-WASM from CDN
This imports all of Tabulator from CDN
Now, let's make a helper function to wrap up loading and instantiating DuckDB (this is just a wrapper around DuckDB's recommended steps):
Now, we can start using DuckDB!
This gets us a DuckDB object we can use to connect to and perform operations on.
This wires up the database to the db JavaScript variable
There's a decent amount of SQL inside one await db.query() call block, so we'll just focus on the SQL in two phases.
Each create table line tells DuckDB where the remote databases are and gives them local table names.
This evalutes the query and returns an array of Arrow proxy objects
This turns the array of proxy objects into a regular JavaScript array of objects
Now for the Tabulator part!
We define a Tabulator custom formatter function which we'll use when we configure the table.
This makes a new Tabulator object and tells it the element id we're targeting
This is the height of the table
This is the array we just made
This will make it fit to the width of the container and hide columns, if needed
This is rendering metadata information
Each of these lines configures on columns. For the day field, we make sure to use a data sorter
For these number value columns, we right align them and use our fancy formatter function. I also set font-variant-numeric: tabular-nums; in CSS for all .tabulator-cell classed elements.
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.