applyOrder static method
SqlStatement
applyOrder(
- SqlStatement statement,
- TetherColumn column, {
- bool ascending = true,
- bool nullsFirst = false,
Adds an ORDER BY clause to a SqlStatement. Replaces existing ORDER BY.
Implementation
static SqlStatement applyOrder(
SqlStatement statement,
TetherColumn column, {
bool ascending = true,
bool nullsFirst = false,
}) {
if (statement.operationType != SqlOperationType.select) {
print("Warning: Applying ORDER BY to non-SELECT statement.");
// Or throw? For now, allow but it might have no effect.
}
final direction = ascending ? 'ASC' : 'DESC';
final nullsHandling = nullsFirst ? 'NULLS FIRST' : 'NULLS LAST';
final orderByClause = '${column.dbName} $direction $nullsHandling';
return statement.copyWith(orderBy: orderByClause);
}