Ducklings API Documentation
    Preparing search index...

    DuckDB database instance for Cloudflare Workers.

    import { init, DuckDB, AccessMode } from '@ducklings/workers';
    import wasmModule from '@ducklings/workers/wasm';

    await init({ wasmModule });

    // Default configuration (httpfs enabled, config locked)
    const db = new DuckDB();

    // Or with custom security configuration
    const secureDb = new DuckDB({
    accessMode: AccessMode.READ_ONLY,
    lockConfiguration: true,
    });

    const conn = db.connect();
    const result = await conn.query('SELECT 42 as answer');
    console.log(result);

    conn.close();
    db.close();
    Index

    Constructors

    Methods

    • Read a registered file back out as bytes.

      The mirror of registerFileBuffer, and how a query's output leaves the filesystem — COPY (…) TO 'x.parquet', then this.

      Parameters

      • name: string

        File name to read

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The file's contents

      await conn.query("COPY (SELECT 42 AS answer) TO 'out.parquet' (FORMAT PARQUET)");
      const bytes = await db.copyFileToBuffer('out.parquet');
    • Register an in-memory buffer as a file DuckDB can read by name.

      Useful when the bytes are already in hand — fetched from object storage through a platform binding, say — and there is no URL DuckDB could httpfs instead. Mirrors registerFileBuffer in @ducklings/browser, which has had this API all along.

      Parameters

      • name: string

        File name to register, optionally with directories

      • buffer: Uint8Array

        The file's contents

      Returns Promise<void>

      await db.registerFileBuffer('data.csv', new TextEncoder().encode('id\n1\n'));
      const rows = await conn.query("SELECT * FROM read_csv('data.csv')");
    • Register text as a file, encoded as UTF-8.

      Parameters

      • name: string

        File name to register

      • text: string

        The file's contents

      Returns Promise<void>