QLite: Allow to easily fetch a single row from table

This commit is contained in:
Marvin W 2018-06-19 12:52:00 +02:00
parent 3a00177a51
commit 0ceaaadb20
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A

View file

@ -98,10 +98,16 @@ public class QueryBuilder : StatementBuilder {
} }
public QueryBuilder limit(int limit) { 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; this.limit_val = limit;
return this; return this;
} }
public QueryBuilder single() {
this.single_result = true;
return limit(1);
}
public int64 count() { public int64 count() {
this.column_selector = @"COUNT($column_selector) AS count"; this.column_selector = @"COUNT($column_selector) AS count";
this.single_result = true; this.single_result = true;
@ -117,8 +123,8 @@ public class QueryBuilder : StatementBuilder {
return new RowOption(row_()); return new RowOption(row_());
} }
public T get<T>(Column<T> field) { public T get<T>(Column<T> field, T def = null) {
return row()[field]; return row().get(field, def);
} }
internal override Statement prepare() { internal override Statement prepare() {