sqrolls
Advanced tools
Comparing version 0.5.2 to 0.6.1
@@ -99,2 +99,9 @@ import * as pr from './predicates'; | ||
whereIsLikeIf(field: string, pattern: string, check: boolean): T; | ||
/** | ||
* Adds a set membership check | ||
* | ||
* @param field The field name | ||
* @param args The value list | ||
*/ | ||
whereIn(field: string, ...args: unknown[]): T; | ||
} |
@@ -137,3 +137,13 @@ "use strict"; | ||
} | ||
/** | ||
* Adds a set membership check | ||
* | ||
* @param field The field name | ||
* @param args The value list | ||
*/ | ||
whereIn(field, ...args) { | ||
this.predicates.push(pr.isIn(field, args)); | ||
return this.getThis(); | ||
} | ||
} | ||
exports.PredicateBaseBuilder = PredicateBaseBuilder; |
@@ -8,6 +8,2 @@ "use strict"; | ||
class Insert extends basebuilders_1.BaseBuilder { | ||
constructor() { | ||
super(); | ||
this.values = []; | ||
} | ||
static builder() { | ||
@@ -19,2 +15,6 @@ return new Insert(); | ||
} | ||
constructor() { | ||
super(); | ||
this.values = []; | ||
} | ||
/** | ||
@@ -21,0 +21,0 @@ * @param table The table to insert into |
@@ -42,3 +42,3 @@ /** | ||
/** | ||
* `<field> is LIKE <arg>` check between a field and the string pattern | ||
* `<field> LIKE <arg>` check between a field and the string pattern | ||
* | ||
@@ -49,1 +49,8 @@ * @param field The field name | ||
export declare function isLike(field: string, pattern: string): Predicate; | ||
/** | ||
* `<field> IN (<args>)` check between a field and the given args | ||
* | ||
* @param field The field name | ||
* @param args The set values | ||
*/ | ||
export declare function isIn(field: string, args: unknown[]): Predicate; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isLike = exports.isNotNull = exports.isNull = exports.isNotEqual = exports.isEqual = exports.Predicate = void 0; | ||
exports.isIn = exports.isLike = exports.isNotNull = exports.isNull = exports.isNotEqual = exports.isEqual = exports.Predicate = void 0; | ||
/** | ||
@@ -61,3 +61,3 @@ * Defines a sql predicate statement used to narrow queries. | ||
/** | ||
* `<field> is LIKE <arg>` check between a field and the string pattern | ||
* `<field> LIKE <arg>` check between a field and the string pattern | ||
* | ||
@@ -71,1 +71,12 @@ * @param field The field name | ||
exports.isLike = isLike; | ||
/** | ||
* `<field> IN (<args>)` check between a field and the given args | ||
* | ||
* @param field The field name | ||
* @param args The set values | ||
*/ | ||
function isIn(field, args) { | ||
const wildcards = args.map(() => '?').join(','); | ||
return new Predicate(`${field} IN (${wildcards})`, args); | ||
} | ||
exports.isIn = isIn; |
@@ -31,25 +31,25 @@ import { PredicateBaseBuilder } from './basebuilders'; | ||
* | ||
* @param val The result set limit | ||
* @param limit The result set limit | ||
*/ | ||
limit(val: number): Select; | ||
limit(limit: number): Select; | ||
/** | ||
* Sets an offset on the select query | ||
* | ||
* @param val The result set offset | ||
* @param offset The result set offset | ||
*/ | ||
offset(val: number): Select; | ||
offset(offset: number): Select; | ||
/** | ||
* Sets a limit on the select query if predicate is true | ||
* | ||
* @param val The result set limit | ||
* @param limit The result set limit | ||
* @param check The conditional check | ||
*/ | ||
limitIf(val: number, check: boolean): Select; | ||
limitIf(limit: number | undefined, check: boolean): Select; | ||
/** | ||
* Sets an offset on the select query | ||
* | ||
* @param val The result set offset | ||
* @param offset The result set offset | ||
* @param check The conditional check | ||
*/ | ||
offsetIf(val: number, check: boolean): Select; | ||
offsetIf(offset: number | undefined, check: boolean): Select; | ||
/** | ||
@@ -56,0 +56,0 @@ * Builds the final select statement. |
@@ -44,6 +44,6 @@ "use strict"; | ||
* | ||
* @param val The result set limit | ||
* @param limit The result set limit | ||
*/ | ||
limit(val) { | ||
this._limit = val; | ||
limit(limit) { | ||
this._limit = limit; | ||
return this; | ||
@@ -54,6 +54,6 @@ } | ||
* | ||
* @param val The result set offset | ||
* @param offset The result set offset | ||
*/ | ||
offset(val) { | ||
this._offset = val; | ||
offset(offset) { | ||
this._offset = offset; | ||
return this; | ||
@@ -64,8 +64,8 @@ } | ||
* | ||
* @param val The result set limit | ||
* @param limit The result set limit | ||
* @param check The conditional check | ||
*/ | ||
limitIf(val, check) { | ||
if (check) { | ||
this.limit(val); | ||
limitIf(limit, check) { | ||
if (limit !== undefined && check) { | ||
this.limit(limit); | ||
} | ||
@@ -77,8 +77,8 @@ return this; | ||
* | ||
* @param val The result set offset | ||
* @param offset The result set offset | ||
* @param check The conditional check | ||
*/ | ||
offsetIf(val, check) { | ||
if (check) { | ||
this.offset(val); | ||
offsetIf(offset, check) { | ||
if (offset !== undefined && check) { | ||
this.offset(offset); | ||
} | ||
@@ -95,3 +95,5 @@ return this; | ||
stmt += ' WHERE ' + this.predicates.map(p => p.clause).join(' AND '); | ||
const _args = this.predicates.filter(p => p.hasArg()).map(p => p.arg); | ||
const _args = this.predicates | ||
.filter(p => p.hasArg()) | ||
.flatMap(p => p.arg); | ||
args.push(..._args); | ||
@@ -98,0 +100,0 @@ } |
@@ -8,2 +8,5 @@ "use strict"; | ||
class Update extends basebuilders_1.PredicateBaseBuilder { | ||
static builder() { | ||
return new Update(); | ||
} | ||
constructor() { | ||
@@ -13,5 +16,2 @@ super(); | ||
} | ||
static builder() { | ||
return new Update(); | ||
} | ||
getThis() { | ||
@@ -18,0 +18,0 @@ return this; |
{ | ||
"name": "sqrolls", | ||
"version": "0.5.2", | ||
"description": "sql builder library", | ||
"keywords": [ | ||
"sqlite3", | ||
"mysql", | ||
"query builder" | ||
], | ||
"main": "./dist/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/sugatpoudel/sqrolls.git" | ||
}, | ||
"author": "tagus", | ||
"license": "MIT", | ||
"files": [ | ||
"dist/**/*" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "jest", | ||
"prepublishOnly": "yarn test", | ||
"prepare": "yarn build" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.9", | ||
"@typescript-eslint/eslint-plugin": "^3.8.0", | ||
"@typescript-eslint/parser": "^3.8.0", | ||
"eslint": "^7.6.0", | ||
"jest": "^26.2.2", | ||
"ts-jest": "^26.1.4", | ||
"typescript": "^3.9.7" | ||
} | ||
"name": "sqrolls", | ||
"version": "0.6.1", | ||
"description": "sql builder library", | ||
"keywords": [ | ||
"sqlite3", | ||
"mysql", | ||
"query builder" | ||
], | ||
"main": "./dist/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/sugatpoudel/sqrolls.git" | ||
}, | ||
"author": "tagus", | ||
"license": "MIT", | ||
"files": [ | ||
"dist/**/*" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "jest", | ||
"prepublishOnly": "yarn test", | ||
"prepare": "yarn build" | ||
}, | ||
"dependencies": { | ||
"eslint": "^8.48.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.4", | ||
"@typescript-eslint/eslint-plugin": "^6.5.0", | ||
"@typescript-eslint/parser": "^6.5.0", | ||
"jest": "^29.6.4", | ||
"ts-jest": "^29.1.1", | ||
"typescript": "^5.2.2" | ||
} | ||
} |
@@ -93,2 +93,16 @@ # sqrolls | ||
Selecting all users with ids in the given list. | ||
```js | ||
const qb = Select.builder() | ||
.select('*') | ||
.from('users') | ||
.whereIn('id', 1, 2, 3, 4) | ||
const [ stmt, args ] = qb.toSQL(); | ||
// stmt: 'SELECT * FROM users WHERE id IN (?,?,?,?)' | ||
// args: [1, 2, 3, 4] | ||
``` | ||
### inserts | ||
@@ -95,0 +109,0 @@ |
24660
6
726
168
1
+ Addedeslint@^8.48.0
+ Added@eslint-community/eslint-utils@4.4.0(transitive)
+ Added@eslint-community/regexpp@4.10.1(transitive)
+ Added@eslint/eslintrc@2.1.4(transitive)
+ Added@eslint/js@8.57.0(transitive)
+ Added@humanwhocodes/config-array@0.11.14(transitive)
+ Added@humanwhocodes/module-importer@1.0.1(transitive)
+ Added@humanwhocodes/object-schema@2.0.3(transitive)
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Added@ungap/structured-clone@1.2.0(transitive)
+ Addedacorn@8.11.3(transitive)
+ Addedacorn-jsx@5.3.2(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedargparse@2.0.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcallsites@3.1.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcross-spawn@7.0.3(transitive)
+ Addeddebug@4.3.5(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addeddoctrine@3.0.0(transitive)
+ Addedescape-string-regexp@4.0.0(transitive)
+ Addedeslint@8.57.0(transitive)
+ Addedeslint-scope@7.2.2(transitive)
+ Addedeslint-visitor-keys@3.4.3(transitive)
+ Addedespree@9.6.1(transitive)
+ Addedesquery@1.5.0(transitive)
+ Addedesrecurse@4.3.0(transitive)
+ Addedestraverse@5.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfile-entry-cache@6.0.1(transitive)
+ Addedfind-up@5.0.0(transitive)
+ Addedflat-cache@3.2.0(transitive)
+ Addedflatted@3.3.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglob-parent@6.0.2(transitive)
+ Addedglobals@13.24.0(transitive)
+ Addedgraphemer@1.4.0(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedignore@5.3.1(transitive)
+ Addedimport-fresh@3.3.0(transitive)
+ Addedimurmurhash@0.1.4(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-path-inside@3.0.3(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjs-yaml@4.1.0(transitive)
+ Addedjson-buffer@3.0.1(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stable-stringify-without-jsonify@1.0.1(transitive)
+ Addedkeyv@4.5.4(transitive)
+ Addedlevn@0.4.1(transitive)
+ Addedlocate-path@6.0.0(transitive)
+ Addedlodash.merge@4.6.2(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedms@2.1.2(transitive)
+ Addednatural-compare@1.4.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedoptionator@0.9.4(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedp-locate@5.0.0(transitive)
+ Addedparent-module@1.0.1(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedprelude-ls@1.2.1(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedresolve-from@4.0.0(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedstrip-json-comments@3.1.1(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedtext-table@0.2.0(transitive)
+ Addedtype-check@0.4.0(transitive)
+ Addedtype-fest@0.20.2(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedword-wrap@1.2.5(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedyocto-queue@0.1.0(transitive)