Node-DuckDB is a thin wrapper on top of DuckDB.
Using it involves:
-
Creating a DuckDB object
-
Creating a Connection object to the DuckDB object
-
Calling Connection.execute or Connection.executeIterator on the Connection object
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.
| 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. |
| 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 |
| Interface | Description |
|---|---|
| IDuckDBConfig | Configuration object for DuckDB |
| IDuckDBOptionsConfig | Options object type for the DuckDB class |
| IExecuteOptions | Options for connection.execute |