Lattice Grid Buy a licence

demo D232

Live pushdown to DuckDB, query by query in Vue

Every sort, filter and page becomes one SQL statement DuckDB answers, with only the window coming back and the generated SQL and timing on screen

createPushdownSource · duckdbAdapter · lastPlan()

This grid turns every sort, filter and page into a single SQL statement DuckDB answers, with only the visible window coming back, and shows the generated SQL and its timing. It makes the query-per-interaction model visible, so you see exactly what the grid asks the database for.

Building…
Loading a live grid…

This is the Vue 3 version. A createLatticeGrid component takes the configuration through v-bind, and reactive data flows straight into the grid, so it updates the way the rest of your Vue app does.

The configuration

<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.min.css">
<style>
  #grid > div { height: 560px; }
</style>
<div id="app"></div>

<script type="module">
  import * as Vue from 'https://esm.sh/vue@3/dist/vue.esm-browser.prod.js';
  import * as lattice from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/lattice-grid.esm.min.js';
  import createLatticeGrid from 'https://cdn.latticegrid.dev/lattice-grid@1.108.0/modules/vue.esm.min.js';
  import * as duckdb from 'https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.29.0/+esm';

  const { createGrid, duckdbAdapter, createPushdownSource } = lattice;
  const LatticeGrid = createLatticeGrid({ vue: Vue, createGrid });

  // Lattice ships no engine. The page starts DuckDB-Wasm itself and hands the
  // adapter a live connection; the grid loads none of it, so the bundle is the
  // same size whether this is used or not.
  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 streams the file, so a host
  // that honours range requests lets DuckDB read only the bytes a query touches.
  const adapter = duckdbAdapter({
    connection,
    from: "read_parquet('/demo-data/readings.parquet')",
  });
  const source = createPushdownSource({
    adapter,
    compute: lattice,   // the grid finishes anything SQL could not express
    pageSize: 200,      // only the visible window comes back, per interaction
  });

  // Wrap execute to show the statement DuckDB ran and how long it took.
  const inner = adapter.execute.bind(adapter);
  adapter.execute = async (query, request) => {
    const started = performance.now();
    const result = await inner(query, request);
    const ms = Math.round(performance.now() - started);
    const f = adapter.sqlFor(query);
    const out = document.getElementById('sql');
    if (out) out.textContent = f.sql + '\n-- ' + ms + ' ms, ' + result.rows.length + ' of ' + (result.total ?? '?') + ' rows';
    return result;
  };

  Vue.createApp({
    components: { LatticeGrid },
    data() {
      return {
        config: {
          rowKey: 'reading_id',
          toolPanel: { side: 'left', panels: ['filters', 'columns'] },
          columns: [
            { field: 'reading_id', title: '#', type: 'number', layout: { width: 110 } },
            { 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' },
            { field: 'taken_at', title: 'Taken', type: 'dateString' },
          ],
          source,   // a hundred thousand rows; DuckDB answers each filter and sort in SQL
        },
      };
    },
    template: `
      <div id="grid"><lattice-grid v-bind="config" /></div>
      <pre id="sql" style="margin-top: 12px"></pre>
    `,
  }).mount('#app');
</script>