DuckDbDbHelper

A helper class that is being used to retrieve the schema information (columns, primary/identity key) of a DuckDB table.

This class implements IDbHelper for DuckDB. It queries information_schema.columns (joined against duckdb_constraints() for primary-key detection) to build the list of DbField objects RepoDB uses internally to generate SQL statements.

It is automatically registered by DuckDbBootstrap — you do not need to instantiate it directly under normal use.

Properties

Name Description
DbTypeResolver The IResolver<string, Type> used to convert a DuckDB column data type (e.g. VARCHAR) into its equivalent .NET CLR type. Defaults to DuckDbTypeNameToClientTypeResolver.

Schema Discovery

DuckDB’s information_schema.columns has no MySQL-style COLUMN_KEY/EXTRA columns, so primary-key detection instead joins against duckdb_constraints() (constraint_type = 'PRIMARY KEY'). A column is treated as an identity when its default expression references a sequence via nextval(...) — DuckDB has no native AUTO_INCREMENT, so a sequence-backed DEFAULT is the closest analog. A parameterized type name (e.g. DECIMAL(18,4)) is stripped down to its base name (DECIMAL) before being resolved to a CLR type.

Identity Retrieval

GetScopeIdentity/GetScopeIdentityAsync always throw NotSupportedException — DuckDB has no session-scoped “last identity” function (unlike MySQL’s LAST_INSERT_ID() or PostgreSQL’s lastval()). Identity/primary key values are instead returned via a RETURNING clause appended directly onto the Insert/InsertAll/Merge/MergeAll statement itself (see DuckDbStatementBuilder), so this path is effectively unreachable in normal use.

Parameter Name Handling

RepoDb.Core creates every ad-hoc DuckDBParameter with its ParameterName already carrying the provider’s $ placeholder sigil (matching the ADO.NET convention used by SqlClient/Npgsql/MySqlConnector). DuckDB.NET does not follow that convention — it requires the bare name, matching what follows $ in the command text. This class strips the sigil from every parameter’s ParameterName right after it is created, so parameters bind correctly regardless of call path.

Usability

Only override this if you need a custom type resolver.

var dbHelper = new DuckDbDbHelper(new MyCustomDuckDbDbTypeNameToClientTypeResolver());
DbHelperMapper.Add<DuckDBConnection>(dbHelper, true);