getListByField method
Perform a query with a where clause fieldName
= fieldValue
unles the like
is true in which case we perform
fieldName
like fieldValue
.
You can do pagination by passing offset
and limit
.
Sort the results by passing orderBy
and sortDirection
Implementation
Future<List<E>> getListByField(String fieldName, String fieldValue,
{bool like = false,
int offset = 0,
int limit = 20,
String? orderBy,
SortDirection sortDirection = SortDirection.asc}) async {
var sql = 'select * from $_tablename ';
if (like) {
sql += 'where `$fieldName` like ? ';
} else {
sql += 'where `$fieldName` = ? ';
}
if (orderBy != null) {
sql += 'order by $orderBy ${sortDirection.name} ';
}
sql += 'limit $offset, $limit ';
return query(sql, [fieldValue]);
}