DuckDB-WASM
    Preparing search index...

    Class AsyncDuckDB

    An interface for the async DuckDB bindings

    Implements

    Index

    Constructors

    Accessors

    Methods

    • Cancel a pending query.

      On the threads bundle the worker runs a poll to its end before it reads another message, so the query is interrupted through shared memory first (getInterruptHandle): a running poll stops at the engine's next check and fails with an interrupt error, and in-flight HTTP requests of the query are abandoned. The cancel message then ends the query in the worker, if the poll has not already ended it.

      Parameters

      • conn: number

      Returns Promise<boolean>

    • Haybarn: download, hash and compile extensions ahead of LOAD.

      In browsers, LOAD downloads each extension synchronously and hashes it with SHA-256 compiled to wasm before checking its signature, then compiles it. This does that work in the worker ahead of time: the downloads run in parallel, the hash is computed with WebCrypto and the module is compiled with WebAssembly.compileStreaming. A later LOAD <name> that resolves to the same URL then only checks the signature, against that hash, and dlopen uses the compiled module once the check has passed. Settings that change the URL (such as custom_extension_repository, or INSTALL <name> FROM <repository> / VERSION) must come first.

      Call it while setting up the session, before running queries. Requests sent while a prefetch runs wait for it.

      Resolves to the names that are held for LOAD, once every download has finished, failed or timed out (after timeoutMs, 30 seconds by default). A name that can't be resolved or downloaded is skipped, leaving the download to LOAD, which reports any error; so are extensions that are already loaded. Each prefetched extension serves one LOAD, at most 256 MiB is held for LOADs that haven't run yet, and reset() or open() drops what no LOAD took. Does nothing in Node.js.

      Parameters

      • names: string[]
      • OptionaltimeoutMs: number

      Returns Promise<string[]>

    • Register a SharedArrayBuffer of at least 4 bytes through which any thread can cancel the most recently started pending query: Atomics.store(new Int32Array(sab), 0, 1). The flag is checked before each poll and every 50 ms while a pending query runs; a cancel resets it to 0 and goes through cancelPendingQuery, so on the threads bundle it also interrupts a poll that is running. For a specific connection use cancelSent() or getInterruptHandle. Registering again replaces the buffer.

      Parameters

      • sab: SharedArrayBuffer

      Returns void

    • Prepare an opfs:// file (or the files a glob pattern matches) for the next queries, returns their names. Registered files are held open until they are dropped, for writing unless mode is 'read'

      Parameters

      • name: string
      • mode: OPFSAccessMode = 'write'

      Returns Promise<string[]>