get<T> method

Future<T?> get<T>(
  1. Object tableEntityInstance,
  2. String afterWhere
)

Returns a single entity of type T matching the afterWhere clause, or null when no row matches.

Throws DatabaseException if the entity table does not exist.

Implementation

Future<T?> get<T>(Object tableEntityInstance, String afterWhere) async {
  final List<Map<String, Object?>> rows = await (await db).transaction(
    (txn) => txn.rawQuery(
      'SELECT * FROM ${T.toString()} WHERE ${_sanitizeWhere(afterWhere)}',
    ),
  );
  if (rows.isEmpty) return null;
  return (tableEntityInstance as dynamic).fromMap(rows.first) as T;
}