Ducklings API Documentation
    Preparing search index...

    DuckDB database instance.

    This is the main entry point for using DuckDB in WASM. Create a database instance, then create connections to execute queries.

    import { init, DuckDB } from '@ducklings/browser';

    await init();

    const db = new DuckDB();
    const conn = await db.connect();

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

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

    Constructors

    Methods

    • Export a file to a buffer.

      Parameters

      • name: string

        The virtual file name to export

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The file contents

    • Internal

      Post a request to the worker and return a promise for the response.

      Type Parameters

      • T

      Parameters

      • type: WorkerRequestType
      • Optionaldata: unknown
      • Optionaltransfer: Transferable[]

      Returns Promise<T>

    • Register an in-memory buffer as a virtual file.

      Parameters

      • name: string

        The virtual file name to use

      • buffer: Uint8Array

        The file contents

      Returns Promise<void>

      const csvData = new TextEncoder().encode('id,name\n1,Alice\n2,Bob');
      await db.registerFileBuffer('data.csv', csvData);
      const rows = await conn.query("SELECT * FROM read_csv('/data.csv')");
    • Register a text string as a virtual file.

      Parameters

      • name: string

        The virtual file name to use

      • text: string

        The file contents as a string

      Returns Promise<void>

    • Register a remote file by URL.

      Parameters

      • name: string

        The virtual file name to use

      • url: string

        The URL to fetch the file from

      • Optionalprotocol: string

        Optional protocol hint ('HTTP' or 'HTTPS')

      • OptionaldirectIO: boolean

        Whether to use direct I/O

      Returns Promise<void>

      await db.registerFileURL('data.parquet', 'https://example.com/data.parquet');
      const rows = await conn.query("SELECT * FROM 'data.parquet'");
    • Creates a new DuckDB database and initializes the WASM module if needed.

      This is a convenience method that combines init() and connect().

      Returns Promise<Connection>

      Promise that resolves to a new Connection instance

      const conn = await DuckDB.createConnection();
      const rows = await conn.query('SELECT 42 as answer');