Class SqlStructuredStoreBase
Shared base for the ADO.NET-backed IStructuredStore providers (MySql, Sqlite, Postgres).
Holds the write/query/read members whose SQL-building logic is identical across the three
dialects, expressed over DbConnection/DbCommand/
DbTransaction/DbDataReader and parameterized through the abstract
hooks declared first.
Inheritance
SqlStructuredStoreBase
Assembly: Serenity.StructuredPersistence.Infrastructure.Providers.Sql.dll
Syntax
public abstract class SqlStructuredStoreBase
Constructors
SqlStructuredStoreBase()
Declaration
protected SqlStructuredStoreBase()
Fields
IDENTITY_COLUMN
Declaration
protected const string IDENTITY_COLUMN = "id"
Field Value
POSITION_COLUMN
Declaration
protected const string POSITION_COLUMN = "srn_position"
Field Value
ROW_RANK_COLUMN
Declaration
protected const string ROW_RANK_COLUMN = "srn_row_rank"
Field Value
Properties
PositionLowerBoundFunction
Declaration
protected abstract string PositionLowerBoundFunction { get; }
Property Value
TimeoutSeconds
Connect/command timeout, in seconds, from this store's configuration.
Declaration
protected abstract int TimeoutSeconds { get; }
Property Value
Methods
AddParameterValue(DbCommand, string, object)
Declaration
protected void AddParameterValue(DbCommand command, string parameterName, object value)
Parameters
AppendOrderByClause(StringBuilder, IReadOnlyList<OrderField>)
Appends an ORDER BY clause, including the dialect's null-placement convention.
Declaration
protected abstract void AppendOrderByClause(StringBuilder sql, IReadOnlyList<OrderField> ordering)
Parameters
ApplyTrimIfNeededAsync(DbConnection, DbTransaction, StoreTable, StructuredTrim, CancellationToken)
Declaration
protected Task ApplyTrimIfNeededAsync(DbConnection connection, DbTransaction transaction, StoreTable table, StructuredTrim trim, CancellationToken token)
Parameters
Returns
BuildCollapsedSelect(StoreTable, IReadOnlyList<FieldFilter>, IReadOnlyList<string>, IReadOnlyList<OrderField>, DbCommand)
Builds the SELECT producing filtered records collapsed to the first row per distinct-by
group under the ordering (via ROW_NUMBER() OVER (PARTITION BY ...)), or a plain
filtered SELECT when no distinct-by fields are given.
Declaration
protected string BuildCollapsedSelect(StoreTable table, IReadOnlyList<FieldFilter> filters, IReadOnlyList<string> distinctBy, IReadOnlyList<OrderField> ordering, DbCommand command)
Parameters
Returns
BuildEqualityPredicate(FieldFilter, DbCommand, string)
Declaration
protected string BuildEqualityPredicate(FieldFilter targetKey, DbCommand command, string parameterName)
Parameters
Returns
BuildFilterPredicate(FieldFilter, DbCommand, string)
Declaration
protected string BuildFilterPredicate(FieldFilter filter, DbCommand command, string parameterName)
Parameters
Returns
BuildKeyWhereClause(StructuredRecord, IReadOnlyList<string>, DbCommand)
Declaration
protected string BuildKeyWhereClause(StructuredRecord record, IReadOnlyList<string> keyFields, DbCommand command)
Parameters
Returns
BuildParameterKey(string)
Builds the key a parameter is registered under, from a bare parameterName
(no leading @). The SQL text this base builds always references
@{parameterName} regardless of dialect; only the REGISTERED key differs — MySql and
Sqlite register it "@"-prefixed, Npgsql registers it bare.
Declaration
protected abstract string BuildParameterKey(string parameterName)
Parameters
| Type |
Name |
Description |
| string |
parameterName |
|
Returns
BuildWhereClause(IReadOnlyList<FieldFilter>, DbCommand, string)
Builds a parameterized WHERE clause. Null comparison values follow the in-memory engine's
"Null orders lowest" semantics: Equal Null → IS NULL, GreaterThan Null → IS NOT
NULL, LessThan Null → matches nothing, LessThan value → (column < value OR
column IS NULL).
Declaration
protected string BuildWhereClause(IReadOnlyList<FieldFilter> filters, DbCommand command, string parameterPrefix)
Parameters
Returns
ConvertDatabaseValue(object)
Converts a value read back from the driver into its StructuredValue equivalent.
Declaration
protected abstract StructuredValue ConvertDatabaseValue(object databaseValue)
Parameters
| Type |
Name |
Description |
| object |
databaseValue |
|
Returns
CountAsync(StoreTable, IReadOnlyList<FieldFilter>, IReadOnlyList<string>, CancellationToken)
Counts the records matching filters, collapsed to one per
distinctBy group when non-empty. See IStructuredStore.CountAsync.
Declaration
public Task<long> CountAsync(StoreTable table, IReadOnlyList<FieldFilter> filters, IReadOnlyList<string> distinctBy, CancellationToken cancellationToken)
Parameters
Returns
CreateLinkedTimeoutTokenSource(CancellationToken)
Declaration
protected CancellationTokenSource CreateLinkedTimeoutTokenSource(CancellationToken cancellationToken)
Parameters
Returns
DeleteByQueryAsync(StoreTable, IReadOnlyList<FieldFilter>, CancellationToken)
Deletes every record matching filters. See IStructuredStore.DeleteByQueryAsync.
Declaration
public Task DeleteByQueryAsync(StoreTable table, IReadOnlyList<FieldFilter> filters, CancellationToken cancellationToken)
Parameters
Returns
ExecuteTrimAsync(DbConnection, DbTransaction, StoreTable, IReadOnlyList<FieldFilter>, IReadOnlyList<OrderField>, int, CancellationToken)
Deletes every in-scope row beyond the best keepCount. Each dialect needs
its own statement shape (MySql, for one, cannot reference a DELETE's own target table in a
plain subquery).
Declaration
protected abstract Task ExecuteTrimAsync(DbConnection connection, DbTransaction transaction, StoreTable table, IReadOnlyList<FieldFilter> scopeFilters, IReadOnlyList<OrderField> ordering, int keepCount, CancellationToken token)
Parameters
Returns
ExecuteWithFailureHandlingAsync<TResult>(Func<CancellationToken, Task<TResult>>, string, StoreTable, CancellationToken)
Runs operation under this store's failure-handling contract (timeout,
logging, exception wrapping). Each provider implements this independently because SQLite's
synchronous driver needs a thread-pool offload that MySql/Postgres do not.
Declaration
protected abstract Task<TResult> ExecuteWithFailureHandlingAsync<TResult>(Func<CancellationToken, Task<TResult>> operation, string operationName, StoreTable table, CancellationToken callerCancellationToken)
Parameters
Returns
| Type |
Description |
| Task<TResult> |
|
Type Parameters
InsertAsync(StoreTable, StructuredRecord, StructuredTrim, CancellationToken)
Inserts record as a new row, optionally trimming the table down to
trim's keep-count afterward. See IStructuredStore.InsertAsync.
Declaration
public Task InsertAsync(StoreTable table, StructuredRecord record, StructuredTrim trim, CancellationToken cancellationToken)
Parameters
Returns
InsertRecordAsync(DbConnection, DbTransaction, StoreTable, StructuredRecord, CancellationToken)
Declaration
protected Task InsertRecordAsync(DbConnection connection, DbTransaction transaction, StoreTable table, StructuredRecord record, CancellationToken token)
Parameters
Returns
JoinQuoted(IReadOnlyList<string>)
Declaration
protected string JoinQuoted(IReadOnlyList<string> identifiers)
Parameters
Returns
OpenConnectionAsync(CancellationToken)
Opens and returns a ready-to-use connection, applying any dialect-specific setup (pragmas, directory creation, etc.).
Declaration
protected abstract Task<DbConnection> OpenConnectionAsync(CancellationToken token)
Parameters
Returns
QueryWindowAroundAsync(StoreTable, IReadOnlyList<FieldFilter>, IReadOnlyList<string>, IReadOnlyList<OrderField>, FieldFilter, int, CancellationToken)
Returns the records within radius positions of the record matching
targetKey. See IPositionalStructuredStore.QueryWindowAroundAsync.
Declaration
public Task<IReadOnlyList<StructuredRecord>> QueryWindowAroundAsync(StoreTable table, IReadOnlyList<FieldFilter> scope, IReadOnlyList<string> distinctBy, IReadOnlyList<OrderField> ordering, FieldFilter targetKey, int radius, CancellationToken cancellationToken)
Parameters
Returns
Quote(string)
Wraps identifier in the dialect's identifier-quoting syntax.
Declaration
protected abstract string Quote(string identifier)
Parameters
| Type |
Name |
Description |
| string |
identifier |
|
Returns
ReadRecordsAsync(DbCommand, CancellationToken)
Declaration
protected Task<IReadOnlyList<StructuredRecord>> ReadRecordsAsync(DbCommand command, CancellationToken token)
Parameters
Returns
RejectNonFiniteComparisonValue(StructuredRecord, string)
Declaration
protected void RejectNonFiniteComparisonValue(StructuredRecord record, string comparisonField)
Parameters
SignedPosition(string)
Declaration
protected virtual string SignedPosition(string positionExpression)
Parameters
| Type |
Name |
Description |
| string |
positionExpression |
|
Returns
TrimBeyondAsync(StoreTable, IReadOnlyList<FieldFilter>, IReadOnlyList<OrderField>, int, CancellationToken)
Within the records matching scopeFilters, keeps only the best
keepCount — in ordering order — deleting the rest.
See IStructuredStore.TrimBeyondAsync.
Declaration
public Task TrimBeyondAsync(StoreTable table, IReadOnlyList<FieldFilter> scopeFilters, IReadOnlyList<OrderField> ordering, int keepCount, CancellationToken cancellationToken)
Parameters
Returns
UpdateRecordFieldsAsync(DbConnection, DbTransaction, StoreTable, StructuredRecord, long, CancellationToken)
Declaration
protected Task UpdateRecordFieldsAsync(DbConnection connection, DbTransaction transaction, StoreTable table, StructuredRecord record, long existingId, CancellationToken token)
Parameters
Returns