sqrolls
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -7,2 +7,3 @@ import { PredicateBaseBuilder } from './basebuilders'; | ||
private columns; | ||
private orderByCol?; | ||
private constructor(); | ||
@@ -20,2 +21,9 @@ static builder(): Select; | ||
/** | ||
* Specifies the column to sort the queried row by | ||
* | ||
* @param col The column to order by | ||
* @param isDescending Whether to sort in descending order | ||
*/ | ||
orderBy(col: string, isDescending?: boolean): Select; | ||
/** | ||
* Builds the final select statement. | ||
@@ -22,0 +30,0 @@ */ |
@@ -32,2 +32,12 @@ "use strict"; | ||
/** | ||
* Specifies the column to sort the queried row by | ||
* | ||
* @param col The column to order by | ||
* @param isDescending Whether to sort in descending order | ||
*/ | ||
orderBy(col, isDescending = false) { | ||
this.orderByCol = [col, isDescending]; | ||
return this; | ||
} | ||
/** | ||
* Builds the final select statement. | ||
@@ -43,2 +53,6 @@ */ | ||
} | ||
if (this.orderByCol) { | ||
const isDescending = this.orderByCol[1]; | ||
stmt += ' ORDER BY ' + this.orderByCol[0] + (isDescending ? ' DESC' : ' ASC'); | ||
} | ||
return [stmt, args]; | ||
@@ -45,0 +59,0 @@ } |
@@ -39,6 +39,7 @@ "use strict"; | ||
toSQL() { | ||
let stmt = 'UPDATE ' + this.table; | ||
if (this.updates.length > 0) { | ||
stmt += ' SET ' + this.updates.map(u => `${u.field} = ?`).join(', '); | ||
if (this.updates.length === 0) { | ||
throw new Error('empty update statement'); | ||
} | ||
let stmt = 'UPDATE ' + this.table + ' SET '; | ||
stmt += this.updates.map(u => `${u.field} = ?`).join(', '); | ||
const args = this.updates.map(u => u.arg); | ||
@@ -45,0 +46,0 @@ if (this.predicates.length > 0) { |
{ | ||
"name": "sqrolls", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "sql builder library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# sqrolls | ||
![sqrolls tests](https://github.com/sugatpoudel/sqrolls/workflows/sqrolls%20tests/badge.svg) | ||
A simple sql-like expression builder that makes it easy to build *sql-like* expressions | ||
@@ -4,0 +6,0 @@ using a hierarchical builder pattern. The resulting statements should work for most sql |
19499
558
140