SelfSync

Explore your database with JavaScript

The official @duckdb/node-api package runs DuckDB inside Node.js, Bun or Deno. Use it to build your own dashboard, feed a static site or script your analyses in TypeScript.

Runs on
macOS, Windows, Linux
Price
Free, open source
Website
duckdb.org

Get started

  1. Install the package

    In any Node.js project.

    npm install @duckdb/node-api
  2. Open the database

    READ_ONLY guarantees nothing gets modified.

    import { DuckDBInstance } from '@duckdb/node-api';
    
    const instance = await DuckDBInstance.create('selfsync-db.duckdb', {
        access_mode: 'READ_ONLY',
    });
    const connection = await instance.connect();
  3. Run a first query

    getRowObjectsJson() returns plain objects, ready to be serialized or passed to a charting library.

    const reader = await connection.runAndReadAll(`SELECT z_sport AS sport,
           count(*) AS sessions,
           round(sum(z_total_distance) / 1000, 1) AS km
    FROM z_fit_session_mesgs
    GROUP BY ALL
    ORDER BY km DESC;`);
    
    console.table(reader.getRowObjectsJson());

Good to know

  • Pass parameters with connection.runAndReadAll(sql, values) and $1, $2… placeholders instead of concatenating strings.

Other tools

Wondering what a table or a column holds? Browse the FIT file reference.