Class NpgsqlBinaryImporter
- Namespace
- Npgsql
- Assembly
- Npgsql.dll
Provides an API for a binary COPY FROM operation, a high-performance data import mechanism to a PostgreSQL table. Initiated by BeginBinaryImport(string)
public sealed class NpgsqlBinaryImporter : IDisposable, IAsyncDisposable
- Inheritance
-
NpgsqlBinaryImporter
- Implements
- Inherited Members
Remarks
Properties
Timeout
Current timeout
public TimeSpan Timeout { set; }
Property Value
Methods
Close()
Terminates the ongoing binary import and puts the connection back into the idle state, where regular commands can be executed.
Note that if Complete() hasn't been invoked before calling this, the import will be cancelled and all changes will be reverted.
public void Close()
CloseAsync(CancellationToken)
Async terminates the ongoing binary import and puts the connection back into the idle state, where regular commands can be executed.
Note that if CompleteAsync(CancellationToken) hasn't been invoked before calling this, the import will be cancelled and all changes will be reverted.
public ValueTask CloseAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationToken
Returns
Complete()
Completes the import operation. The writer is unusable after this operation.
public ulong Complete()
Returns
CompleteAsync(CancellationToken)
Completes the import operation. The writer is unusable after this operation.
public ValueTask<ulong> CompleteAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationToken
Returns
Dispose()
Terminates the ongoing binary import and puts the connection back into the idle state, where regular commands can be executed.
Note that if Complete() hasn't been invoked before calling this, the import will be cancelled and all changes will be reverted.
public void Dispose()
DisposeAsync()
Async terminates the ongoing binary import and puts the connection back into the idle state, where regular commands can be executed.
Note that if CompleteAsync(CancellationToken) hasn't been invoked before calling this, the import will be cancelled and all changes will be reverted.
public ValueTask DisposeAsync()
Returns
StartRow()
Starts writing a single row, must be invoked before writing any columns.
public void StartRow()
StartRowAsync(CancellationToken)
Starts writing a single row, must be invoked before writing any columns.
public Task StartRowAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationToken
Returns
WriteAsync<T>(T, NpgsqlDbType, CancellationToken)
Writes a single column in the current row as type npgsqlDbType
.
public Task WriteAsync<T>(T value, NpgsqlDbType npgsqlDbType, CancellationToken cancellationToken = default)
Parameters
value
TThe value to be written
npgsqlDbType
NpgsqlDbTypeIn some cases
T
isn't enough to infer the data type to be written to the database. This parameter can be used to unambiguously specify the type. An example is the JSONB type, for whichT
will be a simple string but for whichnpgsqlDbType
must be specified as Jsonb.cancellationToken
CancellationTokenAn optional token to cancel the asynchronous operation. The default value is None.
Returns
Type Parameters
T
The .NET type of the column to be written.
WriteAsync<T>(T, string, CancellationToken)
Writes a single column in the current row as type dataTypeName
.
public Task WriteAsync<T>(T value, string dataTypeName, CancellationToken cancellationToken = default)
Parameters
value
TThe value to be written
dataTypeName
stringIn some cases
T
isn't enough to infer the data type to be written to the database. This parameter and be used to unambiguously specify the type.cancellationToken
CancellationTokenAn optional token to cancel the asynchronous operation. The default value is None.
Returns
Type Parameters
T
The .NET type of the column to be written.
WriteAsync<T>(T, CancellationToken)
Writes a single column in the current row.
public Task WriteAsync<T>(T value, CancellationToken cancellationToken = default)
Parameters
value
TThe value to be written
cancellationToken
CancellationTokenAn optional token to cancel the asynchronous operation. The default value is None.
Returns
Type Parameters
T
The type of the column to be written. This must correspond to the actual type or data corruption will occur. If in doubt, use Write<T>(T, NpgsqlDbType) to manually specify the type.
WriteNull()
Writes a single null column value.
public void WriteNull()
WriteNullAsync(CancellationToken)
Writes a single null column value.
public Task WriteNullAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationToken
Returns
WriteRow(params object?[])
Writes an entire row of columns. Equivalent to calling StartRow(), followed by multiple Write<T>(T) on each value.
public void WriteRow(params object?[] values)
Parameters
values
object[]An array of column values to be written as a single row
WriteRowAsync(CancellationToken, params object?[])
Writes an entire row of columns. Equivalent to calling StartRow(), followed by multiple Write<T>(T) on each value.
public Task WriteRowAsync(CancellationToken cancellationToken = default, params object?[] values)
Parameters
cancellationToken
CancellationTokenAn optional token to cancel the asynchronous operation. The default value is None.
values
object[]An array of column values to be written as a single row
Returns
Write<T>(T)
Writes a single column in the current row.
public void Write<T>(T value)
Parameters
value
TThe value to be written
Type Parameters
T
The type of the column to be written. This must correspond to the actual type or data corruption will occur. If in doubt, use Write<T>(T, NpgsqlDbType) to manually specify the type.
Write<T>(T, NpgsqlDbType)
Writes a single column in the current row as type npgsqlDbType
.
public void Write<T>(T value, NpgsqlDbType npgsqlDbType)
Parameters
value
TThe value to be written
npgsqlDbType
NpgsqlDbTypeIn some cases
T
isn't enough to infer the data type to be written to the database. This parameter can be used to unambiguously specify the type. An example is the JSONB type, for whichT
will be a simple string but for whichnpgsqlDbType
must be specified as Jsonb.
Type Parameters
T
The .NET type of the column to be written.
Write<T>(T, string)
Writes a single column in the current row as type dataTypeName
.
public void Write<T>(T value, string dataTypeName)
Parameters
value
TThe value to be written
dataTypeName
stringIn some cases
T
isn't enough to infer the data type to be written to the database. This parameter and be used to unambiguously specify the type.
Type Parameters
T
The .NET type of the column to be written.