firstWhere<T extends Model> static method
Returns first record matching where() condition.
Implementation
static Future<T?> firstWhere<T extends Model>({
required String field,
String comp = "==",
required dynamic value,
}) async {
final constructor = _jsonConstructors[T];
if (constructor == null) return null;
try {
final maps = await _database.query(
_getTableName<T>(),
where: '$field $comp ?',
whereArgs: [value],
limit: 1,
);
if (maps.isNotEmpty) {
return constructor(maps.first) as T;
}
return null;
} catch (e) {
return null;
}
}