toListWhereColumnHasValueMatch method

Future<List<ISQLiteItem>> toListWhereColumnHasValueMatch(
  1. ISQLiteItem item,
  2. String columnName,
  3. dynamic columnValueOf
)

Retrieves a list of items that match the exact condition for the specified column. This method does not account for case differences; it performs a case-sensitive match.

Example usage: var results = await connection.toListWhere(yourItem, 'column_name', 'value_to_match');

Implementation

Future<List<ISQLiteItem>> toListWhereColumnHasValueMatch(
  ISQLiteItem item,
  String columnName,
  dynamic columnValueOf, // Allow any type (int, double, String, etc.)
) async {
  String condition = '$columnName = ?';
  List<ISQLiteItem> results = [];
  var db = await getOpenDatabase();

  // Remove limit to fetch all results
  var maps = await db.query(
    item.getTableName(),
    where: condition,
    whereArgs: [
      columnValueOf
    ], // Pass the value as an array (can be int, double, or String)
  );

  results = maps.map((map) => item.fromMap(map)).toList();
  return results;
}