import type { DuckDBAppender } from './DuckDBAppender'; import { DuckDBDataChunk } from './DuckDBDataChunk'; import { DuckDBType } from './DuckDBType'; import { ToDuckDBValueConverter } from './ToDuckDBValueConverter'; import { DuckDBValue } from './values'; /** Receives each data chunk a `DuckDBDataChunkWriter` fills. */ export type DuckDBDataChunkSink = (chunk: DuckDBDataChunk) => void; /** * `converter` is optional only when the rows are already `DuckDBValue`s, which * is what `T` defaults to. Supply one to write some other representation — * `JSToDuckDBValueConverter` for plain JS — and `T` follows from it. */ export type DuckDBDataChunkWriterOptions = { /** * How many rows each emitted data chunk holds — its `rowCount`. Defaults to * the DuckDB vector size, which is also the most a data chunk can hold. */ readonly rowsPerDataChunk?: number; } & ([DuckDBValue] extends [T] ? { readonly converter?: ToDuckDBValueConverter; } : { readonly converter: ToDuckDBValueConverter; }); /** * Accumulates rows and emits them as filled data chunks, one per * `rowsPerDataChunk` rows, passing each to `sink`. * * Rows are `DuckDBValue`s by default. Supply a converter to write some other * representation; the row type follows from it. * * const writer = DuckDBDataChunkWriter.forAppender(appender, { * converter: JSToDuckDBValueConverter, * }); * for (const row of rows) { * writer.appendRow(row); * } * writer.flush(); * * `flush` emits whatever is buffered, so call it when done: the last chunk is * usually a partial one. Rows already grouped into chunk-sized batches need no * writer — fill a `DuckDBDataChunk` and pass it to the destination directly. */ export declare class DuckDBDataChunkWriter { private readonly types; private readonly sink; private readonly rowsPerDataChunk; private readonly converter?; private rows; constructor(types: readonly DuckDBType[], sink: DuckDBDataChunkSink, options?: DuckDBDataChunkWriterOptions); /** * A writer that appends each filled data chunk to `appender`, using the * appender's own column types. * * Equivalent to constructing one with those types and a sink that calls * `appendDataChunk`, but with nothing to keep in step by hand. */ static forAppender(appender: DuckDBAppender, options?: DuckDBDataChunkWriterOptions): DuckDBDataChunkWriter; get bufferedRowCount(): number; /** * Buffers one row, emitting a data chunk once `rowsPerDataChunk` are held. * * The row is copied, so the same array can be reused across calls. */ appendRow(values: readonly (T | null)[]): void; /** * Emits the buffered rows as one data chunk. A no-op when none are * buffered, so it is safe to call more than once. * * The buffer is emptied either way: if converting the rows fails, or the * sink rejects the chunk, those rows are discarded along with the error. * Appending afterwards starts a fresh chunk. */ flush(): void; }