queryOrder method
Adds an 'ORDER BY' clause to the SQL query.
The fields parameter is optional and defaults to an empty list. It should contain the list of fields to order by and the order direction (ASC or DESC).
This method adds an 'ORDER BY' clause to the _select list and then returns the SqlBuilder instance for method chaining.
Usage:
var builder = SqlBuilder();
builder.queryOrder(fields: [['field1', 'ASC'], ['field2', 'DESC']]);
Implementation
SqlBuilder queryOrder({List<List<String>> fields = const []}) {
List<String> cases = [];
for (var field in fields) {
if (fields.length > 2) {
_error +=
'The order statement must have a maximum of two fields. field (ASC|DESC),)';
PrintHandler.warningLogger.e(_error);
throw Exception(_error);
}
cases = [...cases, '${field[0]} ${field[1]}'];
}
_select.add(cases.join(', '));
return this;
}