diff options
author | bobufa <bobufa@users.noreply.github.com> | 2018-08-01 15:20:56 +0200 |
---|---|---|
committer | bobufa <bobufa@users.noreply.github.com> | 2018-08-13 22:39:18 +0200 |
commit | c0844bdea428c10949339960bd16ea5e2a335fb8 (patch) | |
tree | f2e1e3f0257a7d0ef41f052a31eb143f613fb8d6 /qlite/src | |
parent | b0c94641fcf85ed55976e894fea970331ae22892 (diff) | |
download | dino-c0844bdea428c10949339960bd16ea5e2a335fb8.tar.gz dino-c0844bdea428c10949339960bd16ea5e2a335fb8.zip |
add suggestions/auto-complete for search filters
Diffstat (limited to 'qlite/src')
-rw-r--r-- | qlite/src/query_builder.vala | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/qlite/src/query_builder.vala b/qlite/src/query_builder.vala index d1254b53..88f05e04 100644 --- a/qlite/src/query_builder.vala +++ b/qlite/src/query_builder.vala @@ -23,6 +23,9 @@ public class QueryBuilder : StatementBuilder { // ORDER BY [...] private OrderingTerm[]? order_by_terms = {}; + // GROUP BY [...] + private string? group_by_term; + // LIMIT [...] OFFSET [...] private int limit_val; private int offset_val; @@ -125,6 +128,17 @@ public class QueryBuilder : StatementBuilder { return this; } + public QueryBuilder group_by(Column[] columns) { + foreach(Column col in columns) { + if (group_by_term == null) { + group_by_term = col.to_string(); + } else { + group_by_term += @", $col"; + } + } + return this; + } + public QueryBuilder limit(int limit) { if (this.limit_val != 0 && limit > this.limit_val) error("tried to increase an existing limit"); this.limit_val = limit; @@ -162,7 +176,7 @@ public class QueryBuilder : StatementBuilder { } internal override Statement prepare() { - Statement stmt = db.prepare(@"SELECT $column_selector $(table_name == null ? "" : @"FROM $((!) table_name)") $joins WHERE $selection $(OrderingTerm.all_to_string(order_by_terms)) $(limit_val > 0 ? @" LIMIT $limit_val OFFSET $offset_val" : "")"); + Statement stmt = db.prepare(@"SELECT $column_selector $(table_name == null ? "" : @"FROM $((!) table_name)") $joins WHERE $selection $(group_by_term == null ? "" : @"GROUP BY $group_by_term") $(OrderingTerm.all_to_string(order_by_terms)) $(limit_val > 0 ? @" LIMIT $limit_val OFFSET $offset_val" : "")"); for (int i = 0; i < selection_args.length; i++) { selection_args[i].bind(stmt, i+1); } |