where<T extends Model> static method

Future<List<T>> where<T extends Model>({
  1. required String field,
  2. String comp = "==",
  3. required dynamic value,
})

Filters records with comparison.

Supported: ==, !=, >, <, >=, <=

Implementation

static Future<List<T>> where<T extends Model>({
  required String field,
  String comp = "==",
  required dynamic value,
}) async {
  final constructor = _jsonConstructors[T];
  if (constructor == null) return [];

  try {
    final maps = await _database.query(
      _getTableName<T>(),
      where: '$field $comp ?',
      whereArgs: [value],
    );

    return maps.map((map) => constructor(map) as T).toList();
  } catch (e) {
    print('SQLite where error: $e');
    return [];
  }
}