query<T> method
Entities of type T matching where (? placeholders take their
values from whereArgs), sorted by orderBy (inserted as is: never
from user input), limit rows from offset. Returns [] when nothing
matches.
Implementation
Future<List<T>> query<T>(
Object tableEntityInstance, {
String? where,
List<Object?>? whereArgs,
String? orderBy,
int? limit,
int? offset,
}) async {
if (limit != null && limit < 0) {
throw ArgumentError.value(limit, 'limit', 'must not be negative');
}
if (offset != null && offset < 0) {
throw ArgumentError.value(offset, 'offset', 'must not be negative');
}
final StringBuffer sql = StringBuffer(
'SELECT * FROM ${quoteIdentifier(_tableFor<T>())}${whereClause(where)}',
);
final List<Object?> args = toSqlValues(whereArgs).toList();
if (orderBy != null) sql.write(' ORDER BY $orderBy');
if (limit != null || offset != null) {
sql.write(' LIMIT ?');
args.add(limit ?? -1);
}
if (offset != null) {
sql.write(' OFFSET ?');
args.add(offset);
}
final List<Map<String, Object?>> rows = await (await _executor()).select(
sql.toString(),
args,
);
return _entities<T>(tableEntityInstance, rows);
}