demo D231
A hundred thousand rows in DuckDB, no server in Svelte
DuckDB reads a Parquet file in the browser and the whole set is pulled in, so the plant subtotals and the grand total are computed over all 100,000 rows
createPushdownSource · duckdbAdapter · fullDataset
This grid reads a Parquet file with DuckDB in the browser and pulls the whole hundred-thousand-row set through it, so the subtotals and grand total are computed over every row. It shows analytical figures that cover the full dataset, with no server involved.
This is the Svelte version. A use action attaches the grid to a plain element, so no framework runtime is passed in and the component stays small, while the configuration is ordinary Svelte state.
The configuration
<script>
import * as LatticeGrid from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.esm.min.js';
import createLatticeAction from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/svelte.esm.min.js';
import * as duckdb from 'https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/+esm';
const { createGrid, duckdbAdapter, createPushdownSource } = LatticeGrid;
const lattice = createLatticeAction({ createGrid });
// Lattice ships no engine. The component starts DuckDB-Wasm itself and hands
// the adapter a live connection; the grid imports none of it, so the bundle is
// the same size whether this is used or not. The source is ready once the
// connection opens, so the grid mounts behind an {#if}.
let config;
(async () => {
const bundle = await duckdb.selectBundle(duckdb.getJsDelivrBundles());
const worker = await duckdb.createWorker(bundle.mainWorker);
const db = new duckdb.AsyncDuckDB(new duckdb.ConsoleLogger(duckdb.LogLevel.ERROR), worker);
await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
const connection = await db.connect();
// from is any SQL table expression. read_parquet over an HTTP URL streams the
// file; a host that honours range requests lets DuckDB read only the bytes a
// query touches rather than the whole file.
const adapter = duckdbAdapter({
connection,
from: "read_parquet('/demo-data/readings.parquet')",
});
const source = createPushdownSource({
adapter,
compute: LatticeGrid, // the grid finishes anything SQL could not express
pageSize: 200,
});
config = {
rowKey: 'reading_id',
toolPanel: { side: 'left', panels: ['filters', 'columns'] },
columns: [
{ field: 'reading_id', title: '#', type: 'number' },
{ field: 'plant', title: 'Plant', filter: { type: 'set' } },
{ field: 'line', title: 'Line', filter: { type: 'set' } },
{ field: 'product', title: 'Product' },
{ field: 'bore_mm', title: 'Bore', type: 'millimetres',
spec: { lower: 9.95, upper: 10.05, target: 10 } },
{ field: 'cycle_seconds', title: 'Cycle', type: 'seconds' },
{ field: 'in_spec', title: 'In spec', type: 'boolean' },
],
source, // a hundred thousand rows; DuckDB answers each filter and sort in SQL
};
})();
</script>
<svelte:head>
<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.min.css">
</svelte:head>
{#if config}
<div use:lattice={config} style="height: 560px"></div>
{/if}