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