findById<T extends TableRow> method
Future<T?>
findById<T extends TableRow>(
- Object id, {
- Transaction? transaction,
- Include? include,
- LockMode? lockMode,
- LockBehavior? lockBehavior,
Finds a single TableRow by its id or null if no such row exists. It's
often useful to cast the object returned.
var myRow = session.db.findById<MyClass>(myId);
lockMode acquires a row-level lock on the returned row. Requires
a transaction. See LockMode for available lock types.
lockBehavior controls what happens when a row is already locked.
Defaults to LockBehavior.wait. See LockBehavior for options.
Implementation
Future<T?> findById<T extends TableRow>(
Object id, {
Transaction? transaction,
Include? include,
LockMode? lockMode,
LockBehavior? lockBehavior,
}) async {
// ignore: invalid_use_of_visible_for_testing_member
final resolvedTransaction = transaction ?? _session.transaction;
if (lockMode != null && resolvedTransaction == null) {
throw ArgumentError(
'A transaction is required when using row locking. '
'Wrap your query in session.db.transaction().',
);
}
return _databaseConnection.findById<T>(
_session,
id,
transaction: resolvedTransaction,
include: include,
lockMode: lockMode,
lockBehavior: lockBehavior,
);
}