Commit 696a24ba authored by William Naslund's avatar William Naslund

Added order by to the query

parent a91412df
......@@ -31,7 +31,12 @@ export class PGQueryAdapter implements DBQueryAdapter {
// WHERE
if(req.where != null && req.where.trim() != '') {
sql += 'WHERE ' + req.where.trim();
sql += 'WHERE ' + req.where.trim() + ' ';
}
// ORDER BY
if(req.orderBy != null && req.orderBy.trim() != '') {
sql += 'ORDER BY ' + req.orderBy.trim() + ' ';
}
const recordList: DBQueryResponse[] = [];
......
......@@ -92,6 +92,12 @@ export class DBQuery<T extends DBModel> {
return this;
}
/** Adds an order by condition to this query */
public orderBy(sql: string): this {
this.req.orderBy = sql;
return this;
}
/** Adds a related record to be queried */
public parent<P extends DBModel>(model: DBModelConstructor<P>, lookupProperty: keyof T, ...fields: (keyof P)[]): DBQueryParent<P> {
const parentLookup = new DBQueryParent(model, lookupProperty, fields);
......@@ -149,6 +155,7 @@ export interface DBQueryRequest<T extends DBModel = any> {
fields: any[];
where: string;
whereArgs?: any[];
orderBy?: string;
parents: { [name: string]: DBQueryParent<any>; }
children: { [name: string]: DBQueryRequest; }
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment