Skip to content

Latest commit

 

History

History
72 lines (50 loc) · 3.93 KB

node-duckdb.md

File metadata and controls

72 lines (50 loc) · 3.93 KB

Node-DuckDB API

Node-DuckDB API

Node-DuckDB is a thin wrapper on top of DuckDB.

Using it involves:

  1. Creating a DuckDB object

  2. Creating a Connection object to the DuckDB object

  3. Calling Connection.execute or Connection.executeIterator on the Connection object

Example

Do some simple querying and print the result

import { Connection, DuckDB } from "node-duckdb";

async function queryDatabaseWithIterator() {
  // create new database in memory
  const db = new DuckDB();
  // create a new connection to the database
  const connection = new Connection(db);

  // perform some queries
  await connection.executeIterator("CREATE TABLE people(id INTEGER, name VARCHAR);");
  await connection.executeIterator("INSERT INTO people VALUES (1, 'Mark'), (2, 'Hannes'), (3, 'Bob');");
  const result = await connection.executeIterator("SELECT * FROM people;");

  // fetch and print result
  console.log(result.fetchAllRows());

  // release resources
  connection.close();
  db.close();
}

queryDatabaseWithIterator();

For more examples see here.

Classes

Class Description
Connection Represents a DuckDB connection.
DuckDB The DuckDB class represents a DuckDB database instance.
ResultIterator ResultIterator represents the result set of a DuckDB query. Instances of this class are returned by the Connection.executeIterator.

Enumerations

Enumeration Description
AccessMode Access mode specifier
OrderByNullType Null order specifier
OrderType Default sort order specifier
ResultType Specifier for how DuckDB attempts to load the result
RowResultFormat Result format specifier for rows

Interfaces

Interface Description
IDuckDBConfig Configuration object for DuckDB
IDuckDBOptionsConfig Options object type for the DuckDB class
IExecuteOptions Options for connection.execute