sql-love 0.9.2 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +9 -7
- package/assets/sql-love-logo.png +0 -0
- package/dist/src/SelectBuilder/SelectBuilder.d.ts +3 -2
- package/dist/src/SelectBuilder/SelectBuilder.js +9 -4
- package/package.json +1 -1
- package/src/SelectBuilder/SelectBuilder.spec.ts +1 -1
- package/src/SelectBuilder/SelectBuilder.ts +10 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
<img alt="SQL Love Logo" src="https://github.com/kensnyder/sql-love/raw/main/assets/sql-love-logo.png?v=0.9.4" width="250" height="208" />
|
|
2
|
+
|
|
1
3
|
# sql-love
|
|
2
4
|
|
|
3
|
-
[](https://npmjs.com/package/sql-love)
|
|
6
|
+
[](https://npmjs.com/package/sql-love)
|
|
7
|
+
[](https://github.com/kensnyder/sql-love/actions)
|
|
8
|
+
[](https://codecov.io/gh/kensnyder/sql-love)
|
|
9
|
+
[](https://opensource.org/licenses/ISC)
|
|
8
10
|
|
|
9
11
|
Classes for parsing and building SQL select queries in Node
|
|
10
12
|
|
|
@@ -55,9 +57,9 @@ const { sql, bindings } = query.compile();
|
|
|
55
57
|
|
|
56
58
|
// then execute the SQL in your preferred client:
|
|
57
59
|
// like mysql2
|
|
58
|
-
|
|
60
|
+
connection.query(sql, bindings, (err, results, fields) => {});
|
|
59
61
|
// or Prisma
|
|
60
|
-
const result = await prisma.$
|
|
62
|
+
const result = await prisma.$queryRawUnsafe(sql, ...bindings);
|
|
61
63
|
```
|
|
62
64
|
|
|
63
65
|
It is possible to add placeholders to the base query.
|
|
Binary file
|
|
@@ -86,10 +86,10 @@ export default class SelectBuilder {
|
|
|
86
86
|
_compileOFFSET(engineStyle: EngineStyle, offset: number): string;
|
|
87
87
|
/**
|
|
88
88
|
* Get SQL needed to return the found rows of this query
|
|
89
|
-
* @param countExpr The expression to use inside the COUNT()
|
|
90
89
|
* @param engineStyle The database engine style (mssql, mysql, oracle, pg)
|
|
90
|
+
* @param countExpr The expression to use inside the COUNT()
|
|
91
91
|
*/
|
|
92
|
-
compileCount(
|
|
92
|
+
compileCount(engineStyle?: EngineStyle, countExpr?: string): {
|
|
93
93
|
sql: string;
|
|
94
94
|
bindings: any;
|
|
95
95
|
};
|
|
@@ -352,4 +352,5 @@ export default class SelectBuilder {
|
|
|
352
352
|
* @param number The page number (integer greater than 0)
|
|
353
353
|
*/
|
|
354
354
|
page(number: number | string): this;
|
|
355
|
+
fetch(engine: any): void;
|
|
355
356
|
}
|
|
@@ -153,10 +153,10 @@ export default class SelectBuilder {
|
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
155
|
* Get SQL needed to return the found rows of this query
|
|
156
|
-
* @param countExpr The expression to use inside the COUNT()
|
|
157
156
|
* @param engineStyle The database engine style (mssql, mysql, oracle, pg)
|
|
157
|
+
* @param countExpr The expression to use inside the COUNT()
|
|
158
158
|
*/
|
|
159
|
-
compileCount(
|
|
159
|
+
compileCount(engineStyle = 'mysql', countExpr = '*') {
|
|
160
160
|
const query = this.getFoundRowsQuery(countExpr);
|
|
161
161
|
const { sql, bindings } = query.compile(engineStyle);
|
|
162
162
|
if (this._havings.length === 0) {
|
|
@@ -526,7 +526,7 @@ export default class SelectBuilder {
|
|
|
526
526
|
operator = '=';
|
|
527
527
|
}
|
|
528
528
|
operator = operator.toLocaleUpperCase();
|
|
529
|
-
const likeMatch = operator.match(/^(LIKE|NOT LIKE)(?: (\?|\?%|%\?|%\?%))?$/i);
|
|
529
|
+
const likeMatch = operator.match(/^(LIKE|NOT LIKE|ILIKE|NOT ILIKE)(?: (\?|\?%|%\?|%\?%))?$/i);
|
|
530
530
|
if (operator === 'NOT BETWEEN' || operator === 'BETWEEN') {
|
|
531
531
|
// expect a two-item array
|
|
532
532
|
const one = this._bindings.length;
|
|
@@ -535,7 +535,7 @@ export default class SelectBuilder {
|
|
|
535
535
|
this._bindings.push(value[0], value[1]);
|
|
536
536
|
}
|
|
537
537
|
else if (likeMatch) {
|
|
538
|
-
const like = likeMatch[1].toUpperCase(); // Either LIKE
|
|
538
|
+
const like = likeMatch[1].toUpperCase(); // Either "LIKE", "NOT LIKE" etc.
|
|
539
539
|
const infix = likeMatch[2] || '?'; // ONE OF ?% or %?% or %? or ?
|
|
540
540
|
if (Array.isArray(value)) {
|
|
541
541
|
const ors = [];
|
|
@@ -769,4 +769,9 @@ export default class SelectBuilder {
|
|
|
769
769
|
}
|
|
770
770
|
return this;
|
|
771
771
|
}
|
|
772
|
+
fetch(engine) {
|
|
773
|
+
if (engine.$queryRawUnsafe) {
|
|
774
|
+
//
|
|
775
|
+
}
|
|
776
|
+
}
|
|
772
777
|
}
|
package/package.json
CHANGED
|
@@ -600,7 +600,7 @@ describe('compileCount()', () => {
|
|
|
600
600
|
});
|
|
601
601
|
it('should handle a distinct', () => {
|
|
602
602
|
const query = new SelectBuilder('SELECT * FROM posts');
|
|
603
|
-
const { sql, bindings } = query.compileCount('DISTINCT group_id');
|
|
603
|
+
const { sql, bindings } = query.compileCount('mysql', 'DISTINCT group_id');
|
|
604
604
|
expect(trim(sql)).toBe(
|
|
605
605
|
'SELECT COUNT(DISTINCT group_id) AS found_rows FROM posts'
|
|
606
606
|
);
|
|
@@ -187,10 +187,10 @@ export default class SelectBuilder {
|
|
|
187
187
|
|
|
188
188
|
/**
|
|
189
189
|
* Get SQL needed to return the found rows of this query
|
|
190
|
-
* @param countExpr The expression to use inside the COUNT()
|
|
191
190
|
* @param engineStyle The database engine style (mssql, mysql, oracle, pg)
|
|
191
|
+
* @param countExpr The expression to use inside the COUNT()
|
|
192
192
|
*/
|
|
193
|
-
compileCount(
|
|
193
|
+
compileCount(engineStyle: EngineStyle = 'mysql', countExpr: string = '*') {
|
|
194
194
|
const query = this.getFoundRowsQuery(countExpr);
|
|
195
195
|
const { sql, bindings } = query.compile(engineStyle);
|
|
196
196
|
if (this._havings.length === 0) {
|
|
@@ -580,7 +580,7 @@ export default class SelectBuilder {
|
|
|
580
580
|
}
|
|
581
581
|
operator = operator.toLocaleUpperCase();
|
|
582
582
|
const likeMatch = operator.match(
|
|
583
|
-
/^(LIKE|NOT LIKE)(?: (\?|\?%|%\?|%\?%))?$/i
|
|
583
|
+
/^(LIKE|NOT LIKE|ILIKE|NOT ILIKE)(?: (\?|\?%|%\?|%\?%))?$/i
|
|
584
584
|
);
|
|
585
585
|
if (operator === 'NOT BETWEEN' || operator === 'BETWEEN') {
|
|
586
586
|
// expect a two-item array
|
|
@@ -591,7 +591,7 @@ export default class SelectBuilder {
|
|
|
591
591
|
);
|
|
592
592
|
this._bindings.push(value[0], value[1]);
|
|
593
593
|
} else if (likeMatch) {
|
|
594
|
-
const like = likeMatch[1].toUpperCase(); // Either LIKE
|
|
594
|
+
const like = likeMatch[1].toUpperCase(); // Either "LIKE", "NOT LIKE" etc.
|
|
595
595
|
const infix = likeMatch[2] || '?'; // ONE OF ?% or %?% or %? or ?
|
|
596
596
|
if (Array.isArray(value)) {
|
|
597
597
|
const ors = [];
|
|
@@ -842,4 +842,10 @@ export default class SelectBuilder {
|
|
|
842
842
|
}
|
|
843
843
|
return this;
|
|
844
844
|
}
|
|
845
|
+
|
|
846
|
+
fetch(engine) {
|
|
847
|
+
if (engine.$queryRawUnsafe) {
|
|
848
|
+
//
|
|
849
|
+
}
|
|
850
|
+
}
|
|
845
851
|
}
|