Insert data from an Arrow IPC stream buffer into a table.
Creates a new table with the given name from the Arrow IPC data. If the table
already exists, the call is a no-op (uses CREATE TABLE IF NOT EXISTS).
Important: The IPC stream must not contain dictionary-encoded columns.
Flechette's tableFromArrays() defaults to dictionary(utf8()) for string
columns. Use explicit utf8() types to avoid this.
The name of the table to create
Arrow IPC stream bytes (use tableToIPC(table, { format: 'stream' }))
import { tableFromArrays, tableToIPC, utf8 } from '@ducklings/browser';
const table = tableFromArrays(
{ id: [1, 2, 3], name: ['Alice', 'Bob', 'Charlie'] },
{ types: { name: utf8() } } // Required for string columns
);
const ipcBuffer = tableToIPC(table, { format: 'stream' });
await conn.insertArrowFromIPCStream('users', ipcBuffer);
Begins a new transaction.
Closes the connection and releases resources.
Commits the current transaction.
Executes a SQL statement and returns the number of affected rows.
Use this for INSERT, UPDATE, DELETE, or other statements where you don't need to read result rows.
The SQL statement to execute
Promise resolving to the number of rows affected
InternalGet the connection ID.
Insert data from a CSV file.
The name of the table to insert into
The virtual file path of the CSV
Optionaloptions: CSVInsertOptionsOptional CSV parsing options
Insert data from a JSON file.
The name of the table to insert into
The virtual file path of the JSON
Optionaloptions: JSONInsertOptionsOptional JSON parsing options
Prepares a SQL statement for execution.
Prepared statements are more secure (prevent SQL injection) and can be more efficient when executing the same query multiple times with different parameters.
The SQL statement with parameter placeholders (?)
Promise resolving to a PreparedStatement instance
Executes a SQL query and returns the results as an array of objects.
The SQL query to execute
Promise resolving to array of result rows as objects
Executes a SQL query and returns results as a Flechette Arrow Table.
This method is more efficient for large result sets and provides proper Arrow/columnar data representation.
The SQL query to execute
Promise resolving to Arrow Table with query results
Executes a SQL query and returns a streaming result.
This method is more memory-efficient for large result sets as it processes data in chunks rather than loading everything at once.
The SQL query to execute
Promise resolving to AsyncStreamingResult that can be iterated over
Rolls back the current transaction.
A connection to a DuckDB database.
Connections are used to execute queries and manage transactions. All operations are async as they communicate with a Web Worker.
Example