Class DuckDBAppender
Appends rows to a DuckDB table.
public class DuckDBAppender : IDisposable
- Inheritance
-
DuckDBAppender
- Implements
- Inherited Members
Remarks
Instances are not thread-safe. Do not call other methods on the same appender from an AppendRow<TState>(TState, Action<IDuckDBAppenderRow, TState>) callback.
Methods
AppendRow(Action<IDuckDBAppenderRow>)
Appends a complete row using a reusable row instance.
public void AppendRow(Action<IDuckDBAppenderRow> writeRow)
Parameters
writeRowAction<IDuckDBAppenderRow>A callback that appends every column value. This method calls EndRow() after the callback returns.
Remarks
The row is valid only during the callback and must not be retained. The callback must not call other methods on this appender. If the callback or automatic EndRow() fails, the failed row is discarded and no more rows can be appended; the rows completed before the failure are still written when the appender is closed or disposed. Wrap the append in a transaction if you need all-or-nothing.
For large or hot-path loads, prefer the
AppendRow<TState>(TState, Action<IDuckDBAppenderRow, TState>) overload with a
static callback. A callback passed here that captures variables allocates a
closure on every call; passing the captured data as the state argument to that overload
keeps the append allocation-free.
AppendRow<TState>(TState, Action<IDuckDBAppenderRow, TState>)
Appends a complete row using a reusable row instance without exposing that instance as a
return value. The row passed to writeRow is only valid for the duration of
the callback and must not be retained or used after the callback returns.
public void AppendRow<TState>(TState state, Action<IDuckDBAppenderRow, TState> writeRow)
Parameters
stateTStateThe value used to populate the row.
writeRowAction<IDuckDBAppenderRow, TState>A callback that appends every column value. This method calls EndRow() after the callback returns.
Type Parameters
TStateThe type of value used to populate the row.
Remarks
The callback must not call other methods on this appender. If the callback or automatic EndRow() fails, the failed row is discarded and no more rows can be appended; the rows completed before the failure are still written when the appender is closed or disposed. Wrap the append in a transaction if you need all-or-nothing.
This overload is the allocation-free choice for hot paths: use a static
callback and pass any per-row data through state so the callback captures
nothing and no closure is allocated per row.
Clear()
public void Clear()
Close()
public void Close()
CreateRow()
Creates an independent row. The caller must append every column and call EndRow().
public IDuckDBAppenderRow CreateRow()
Returns
Remarks
A new row instance is allocated on every call. Prefer AppendRow<TState>(TState, Action<IDuckDBAppenderRow, TState>), which reuses a single row instance and avoids the per-row allocation; use this method only when you need an independent row instance whose lifetime you control.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()