aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/query_builder.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2018-06-19 12:52:00 +0200
committerMarvin W <git@larma.de>2018-07-11 01:10:26 +0200
commit0ceaaadb201a710baa2b6f358c3b29b4fcc192d6 (patch)
tree75ef4bb10a92ce29ab769c6f3380f239b9a3c547 /qlite/src/query_builder.vala
parent3a00177a51e48d6bafc1e67bab26bc510e6400d8 (diff)
downloaddino-0ceaaadb201a710baa2b6f358c3b29b4fcc192d6.tar.gz
dino-0ceaaadb201a710baa2b6f358c3b29b4fcc192d6.zip
QLite: Allow to easily fetch a single row from table
Diffstat (limited to 'qlite/src/query_builder.vala')
-rw-r--r--qlite/src/query_builder.vala10
1 files changed, 8 insertions, 2 deletions
diff --git a/qlite/src/query_builder.vala b/qlite/src/query_builder.vala
index dbfdef2a..75fe0499 100644
--- a/qlite/src/query_builder.vala
+++ b/qlite/src/query_builder.vala
@@ -98,10 +98,16 @@ public class QueryBuilder : StatementBuilder {
}
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;
return this;
}
+ public QueryBuilder single() {
+ this.single_result = true;
+ return limit(1);
+ }
+
public int64 count() {
this.column_selector = @"COUNT($column_selector) AS count";
this.single_result = true;
@@ -117,8 +123,8 @@ public class QueryBuilder : StatementBuilder {
return new RowOption(row_());
}
- public T get<T>(Column<T> field) {
- return row()[field];
+ public T get<T>(Column<T> field, T def = null) {
+ return row().get(field, def);
}
internal override Statement prepare() {