MssqlRepository<TRow, TKey> class

Reads and writes a table described by MssqlTableBinding.

TKey is a scalar key, generated composite key, or Never for keyless tables.

Constructors

MssqlRepository(MssqlSession session, {required MssqlTableBinding<TRow> binding, String? schema, String? table, MssqlDialect? dialect, MssqlScopeSelection scope = const MssqlScopeSelection.empty(), MssqlClock clock = MssqlClock.serverUtc, MssqlChangeHub? changes, MssqlCapabilityCache? capabilities, MssqlQueryOptions options = MssqlQueryOptions.defaults})
MssqlRepository.withKeyValues(MssqlSession session, {required MssqlTableBinding<TRow> binding, required Map<String, Object?> keyValues(TKey key), String? schema, String? table, MssqlDialect? dialect, MssqlScopeSelection scope = const MssqlScopeSelection.empty(), MssqlClock clock = MssqlClock.serverUtc, MssqlChangeHub? changes, MssqlCapabilityCache? capabilities, MssqlQueryOptions options = MssqlQueryOptions.defaults})
A repository over a table with a composite key needs to know how to take that key apart, which only generated code can say.

Properties

binding → MssqlTableBinding<TRow>
final
capabilities → MssqlCapabilityCache?
Shared dialect cache. Null uses MssqlCapabilityCache.shared.
final
changes → MssqlChangeHub?
Committed-write hub, or null when this repository is not from an AppDatabase.
final
clock → MssqlClock
Which server clock timestamp columns use.
final
dialect → MssqlDialect?
Null means "ask the server once, then remember".
final
hashCode → int
The hash code for this object.
no setterinherited
options → MssqlQueryOptions
Execution settings propagated to reads and relation includes.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scope → MssqlScopeSelection
Immutable selection of soft-delete and global scopes.
final
session → MssqlSession
final
warnings → List<String>
Non-fatal warnings raised while loading relations.
final

Methods

count([MssqlCondition? where]) → Future<int>
createOrFirst(MssqlCondition where, TRow build()) → Future<TRow>
Tries the insert first, then reads the winner after error 2601 or 2627.
decrement(TKey key, String column, {num by = 1}) → Future<int>
delete(TKey key) → Future<int>
Deletes the row with this key.
deleteWhere(MssqlCondition where) → Future<int>
exists(TKey key) → Future<bool>
existsWhere(MssqlCondition where) → Future<bool>
Whether any scoped row matches where, using SELECT TOP 1.
findAll({List<MssqlOrder> orderBy = const <MssqlOrder>[], List<MssqlRelation<TRow, Object?>> include = const []}) → Future<List<TRow>>
findById(TKey key, {List<MssqlRelation<TRow, Object?>> include = const []}) → Future<TRow?>
The row with this key, or null.
findWhere(MssqlCondition where, {List<MssqlOrder> orderBy = const <MssqlOrder>[], List<MssqlRelation<TRow, Object?>> include = const []}) → Future<List<TRow>>
firstOrCreate(MssqlCondition where, TRow build()) → Future<TRow>
Returns the first match or inserts build's row.
firstOrNew(MssqlCondition where, TRow build()) → Future<TRow>
firstOrCreate without the insert: the row, or build's unsaved one.
firstWhere(MssqlCondition where, {List<MssqlOrder> orderBy = const <MssqlOrder>[]}) → Future<TRow?>
The first row matching where, or null.
forceDelete(TKey key) → Future<int>
Removes the row from the table, soft deletes or not.
getById(TKey key, {List<MssqlRelation<TRow, Object?>> include = const []}) → Future<TRow>
The row with this key, or throws MssqlRowNotFoundException.
getOrCreate({required MssqlUniqueMatch key, required MssqlWriteAssignments create, bool restoreExisting = false, bool includeDeleted = false}) → Future<TRow>
Inserts create, or returns the row already owning key.
increment(TKey key, String column, {num by = 1}) → Future<int>
Adds by to a column in place, without reading it first.
insert(TRow row) → Future<TRow>
Inserts row and applies the table's configured readback strategy.
insertAll(List<TRow> rows) → Future<void>
Inserts rows in batches within SQL Server's row and parameter limits.
insertAssignments(MssqlWriteAssignments values) → Future<TRow>
Inserts values and returns the stored row, including defaults.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onlyTrashed() → MssqlRepository<TRow, TKey>
Only soft-deleted rows.
page({required int rows, int offset = 0, required List<MssqlOrder> orderBy, MssqlCondition? where, bool includeTotal = false, List<MssqlRelation<TRow, Object?>> include = const []}) → Future<MssqlPage<TRow>>
One page, and whether another follows.
restore(TKey key) → Future<int>
Clears the deleted-at column, bringing a soft-deleted row back.
toString() → String
A string representation of this object.
inherited
trashed(TKey key) → Future<bool>
Whether the row exists and carries the configured deleted value.
update(TRow row, {Set<String>? columns}) → Future<int>
Updates the identified row, optionally limited to columns.
updateMatching(List<MssqlCondition> where, MssqlWriteAssignments patch, {Object? expectedVersion, int? expectAffected}) → Future<int>
Writes patch to every row matching where.
updateOne(TRow row, {Set<String>? columns}) → Future<void>
update, but insisting that exactly one row changed.
updateOrCreate(MssqlCondition where, TRow build(TRow? existing), {Set<String>? columns}) → Future<TRow>
Updates the row matching where to build's, or inserts it.
updatePatch(TKey key, MssqlWriteAssignments patch, {Object? expectedVersion}) → Future<TRow>
Applies patch, optionally guarded by the last-read expectedVersion.
updateWhere(MssqlCondition where, Map<String, Object?> values) → Future<int>
Writes values to every row matching where, and returns how many changed.
withoutGlobalScopes() → MssqlRepository<TRow, TKey>
Switches every global scope off without changing soft-delete visibility.
withoutScope(String name) → MssqlRepository<TRow, TKey>
Switches a global scope off by name.
withoutTrashed() → MssqlRepository<TRow, TKey>
Back to the default: deleted rows hidden.
withTrashed() → MssqlRepository<TRow, TKey>
Returns a repository that also sees soft-deleted rows.

Operators

operator ==(Object other) → bool
The equality operator.
inherited