sql-love 0.9.1 → 0.9.3

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 CHANGED
@@ -1,12 +1,20 @@
1
1
  ## Change Log
2
2
 
3
- ### v0.9.1
3
+ ### v0.9.3 - 30 Nov 2023
4
+
5
+ - Support parsing and building "ILIKE" and "NOT ILIKE"
6
+
7
+ ### v0.9.2 - 30 Nov 2023
8
+
9
+ - Fixes to readme
10
+
11
+ ### v0.9.1 - 30 Nov 2023
4
12
 
5
13
  - More documentation
6
14
  - GitHub Actions CI
7
15
  - Support for parsing "OFFSET # ROWS"
8
16
  - Support for parsing "FETCH NEXT # ROWS ONLY"
9
17
 
10
- ### v0.9.0
18
+ ### v0.9.0 - 29 Nov 2023
11
19
 
12
20
  - Initial release with `SelectBuilder`
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.3" width="250" height="208" />
2
+
1
3
  # sql-love
2
4
 
3
- [![NPM Link](https://badgen.net/npm/v/sql-love?v=0.9.1)](https://npm.com/package/any-date-parser)
4
- [![Dependencies](https://badgen.net/static/dependencies/0/green?v=0.9.1)](https://npm.com/package/any-date-parser)
5
- [![Build Status](https://github.com/kensnyder/sql-love/actions/workflows/node.js.yml/badge.svg?v=0.9.1)](https://github.com/kensnyder/sql-love/actions)
6
- [![Code Coverage](https://codecov.io/gh/kensnyder/sql-love/branch/main/graph/badge.svg?v=0.9.1)](https://codecov.io/gh/kensnyder/sql-love)
7
- [![ISC License](https://badgen.net/static/license/ISC/green?v=0.9.1)](https://opensource.org/licenses/ISC)
5
+ [![NPM Link](https://badgen.net/npm/v/sql-love?v=0.9.3)](https://npmjs.com/package/sql-love)
6
+ [![Dependencies](https://badgen.net/static/dependencies/0/green?v=0.9.3)](https://npmjs.com/package/sql-love)
7
+ [![Build Status](https://github.com/kensnyder/sql-love/actions/workflows/node.js.yml/badge.svg?v=0.9.3)](https://github.com/kensnyder/sql-love/actions)
8
+ [![Code Coverage](https://codecov.io/gh/kensnyder/sql-love/branch/main/graph/badge.svg?v=0.9.3)](https://codecov.io/gh/kensnyder/sql-love)
9
+ [![ISC License](https://badgen.net/static/license/ISC/green?v=0.9.3)](https://opensource.org/licenses/ISC)
8
10
 
9
11
  Classes for parsing and building SQL select queries in Node
10
12
 
@@ -19,7 +21,6 @@ npm install sql-love
19
21
  - [SelectBuilder](#selectbuilder)
20
22
  - [Parsing base SQL](#parsing-base-sql)
21
23
  - [Building the Query](#building-the-query)
22
- - [Fetching Data](#fetching-data)
23
24
  - [Counting Results](#counting-results)
24
25
  - [Other Methods](#other-methods)
25
26
  - [new SelectBuilder() Limitations](#selectparse-limitations)
@@ -56,9 +57,9 @@ const { sql, bindings } = query.compile();
56
57
 
57
58
  // then execute the SQL in your preferred client:
58
59
  // like mysql2
59
- mysql.query(sql, bindings);
60
+ connection.query(sql, bindings, (err, results, fields) => {});
60
61
  // or Prisma
61
- const result = await prisma.$executeRaw(sql, bindings);
62
+ const result = await prisma.$queryRawUnsafe(sql, ...bindings);
62
63
  ```
63
64
 
64
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(countExpr?: string, engineStyle?: EngineStyle): {
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(countExpr = '*', engineStyle = 'mysql') {
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 or NOT 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sql-love",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "description": "Build SQL queries with JavaScript",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -10,7 +10,8 @@
10
10
  "test-watch": "vitest",
11
11
  "coverage": "vitest run --coverage",
12
12
  "clean": "rimraf dist/ && mkdir dist && touch dist/.gitkeep",
13
- "build": "npm run clean && npx -p typescript tsc --project tsconfig.build.json"
13
+ "build": "npm run clean && npx -p typescript tsc --project tsconfig.build.json",
14
+ "release": "npm i && npm run build && npm publish"
14
15
  },
15
16
  "repository": {
16
17
  "type": "git",
@@ -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(countExpr: string = '*', engineStyle: EngineStyle = 'mysql') {
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 or NOT 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
  }