CockroachDbDbHelper
A helper class that is being used to retrieve the schema information (columns, primary/identity key) of a CockroachDB table.
This class implements IDbHelper for CockroachDB. It queries information_schema.columns (joined against pg_index to detect primary keys, and against pg_namespace to also recognize the session’s temporary schema) to build the list of DbField objects RepoDB uses internally to generate SQL statements.
It is automatically registered by CockroachDbBootstrap — you do not need to instantiate it directly under normal use.
Properties
| Name | Description |
|---|---|
| DbTypeResolver | The IResolver<string, Type> used to convert a CockroachDB column type name into its equivalent .NET CLR type. Defaults to CockroachDbDbTypeNameToClientTypeResolver. |
GetScopeIdentity
GetScopeIdentity/GetScopeIdentityAsync execute SELECT lastval(); against the connection.
Retry on OperationInProgress
If the connection is already mid-operation, GetFields and GetScopeIdentity transparently retry once against a brand-new connection created from the same connection string. The failure is recognized by type name (NpgsqlOperationInProgressException) — RepoDb.Connector.CockroachDb wraps NpgsqlConnection directly rather than translating its exceptions, so Npgsql’s own exception type surfaces as-is.
Date/Time and Array Parameter Handling
After every ad-hoc parameter is created, this helper adjusts its value/DbType so it binds correctly against CockroachDB:
- A
DateOnlyvalue is converted toDateTime(midnight) withDbType.Date, and aTimeOnlyvalue toTimeSpanwithDbType.Time— neither has a direct binding on this connector. - A non-UTC
DateTimevalue is bound asDbType.DateTime2, so its offset-naive value isn’t misread as UTC. - A
DateOnly[]/TimeOnly[]array value has each element converted the same way (toDateTime[]/TimeSpan[]) before binding.
Usability
Only override this if you need a custom type resolver.
var dbHelper = new CockroachDbDbHelper(new MyCustomCockroachDbDbTypeNameToClientTypeResolver());
DbHelperMapper.Add<CockroachDbConnection>(dbHelper, true);