knex 1.0.3 → 1.0.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 CHANGED
@@ -1,5 +1,27 @@
1
1
  # Master (Unreleased)
2
2
 
3
+ # 1.0.4 - 13 March, 2022
4
+
5
+ ### New features:
6
+
7
+ - Add whereLike functions #5044
8
+
9
+ ### Bug fixes:
10
+
11
+ - Fix orWhereJsonPath clause #5022
12
+ - Subquery in on clause missing parenthesis #5049
13
+ - Rework Union Wrapping #5030
14
+ - Oracle: Fix batch inserts with DEFAULT values with OracleDB #2592 #5037
15
+
16
+ ### Typings:
17
+
18
+ - Fix types for "returning" methods #5031
19
+ - createTableLike callback should be optional #5055
20
+
21
+ ### Documentation:
22
+
23
+ - Website URL changed to https://knex.github.io/documentation/
24
+
3
25
  # 1.0.3 - 11 February, 2022
4
26
 
5
27
  ### Bug fixes:
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [knex.js](http://knexjs.org)
1
+ # [knex.js](https://knex.github.io/documentation/)
2
2
 
3
3
  [![npm version](http://img.shields.io/npm/v/knex.svg)](https://npmjs.org/package/knex)
4
4
  [![npm downloads](https://img.shields.io/npm/dm/knex.svg)](https://npmjs.org/package/knex)
@@ -13,15 +13,15 @@
13
13
  A batteries-included, multi-dialect (PostgreSQL, MySQL, CockroachDB, MSSQL, SQLite3, Oracle (including Oracle Wallet Authentication)) query builder for
14
14
  Node.js, featuring:
15
15
 
16
- - [transactions](https://knexjs.org/#Transactions)
17
- - [connection pooling](https://knexjs.org/#Installation-pooling)
18
- - [streaming queries](https://knexjs.org/#Interfaces-Streams)
19
- - both a [promise](https://knexjs.org/#Interfaces-Promises) and [callback](https://knexjs.org/#Interfaces-Callbacks) API
16
+ - [transactions](https://knex.github.io/documentation/#Transactions)
17
+ - [connection pooling](https://knex.github.io/documentation/#Installation-pooling)
18
+ - [streaming queries](https://knex.github.io/documentation/#Interfaces-Streams)
19
+ - both a [promise](https://knex.github.io/documentation/#Interfaces-Promises) and [callback](https://knex.github.io/documentation/#Interfaces-Callbacks) API
20
20
  - a [thorough test suite](https://github.com/knex/knex/actions)
21
21
 
22
22
  Node.js versions 12+ are supported.
23
23
 
24
- * Take a look at the [full documentation](https://knexjs.org) to get started!
24
+ * Take a look at the [full documentation](https://knex.github.io/documentation) to get started!
25
25
  * Browse the [list of plugins and tools](https://github.com/knex/knex/blob/master/ECOSYSTEM.md) built for knex
26
26
  * Check out our [recipes wiki](https://github.com/knex/knex/wiki/Recipes) to search for solutions to some specific problems
27
27
  * In case of upgrading from an older version, see [migration guide](https://github.com/knex/knex/blob/master/UPGRADING.md)
@@ -156,8 +156,8 @@ class Oracledb_Compiler extends Oracle_Compiler {
156
156
  // later position binding will only convert the ? params
157
157
  subSql = self.formatter.client.positionBindings(subSql);
158
158
  const parameterizedValuesWithoutDefaultAndBlob = parameterizedValues
159
- .replace('DEFAULT, ', '')
160
- .replace(', DEFAULT', '')
159
+ .replace(/DEFAULT, /g, '')
160
+ .replace(/, DEFAULT/g, '')
161
161
  .replace('EMPTY_BLOB(), ', '')
162
162
  .replace(', EMPTY_BLOB()', '');
163
163
  return (
@@ -27,12 +27,16 @@ module.exports = [
27
27
  'fullOuterJoin',
28
28
  'crossJoin',
29
29
  'where',
30
- 'whereLike',
31
- 'whereILike',
32
30
  'andWhere',
33
31
  'orWhere',
34
32
  'whereNot',
35
33
  'orWhereNot',
34
+ 'whereLike',
35
+ 'andWhereLike',
36
+ 'orWhereLike',
37
+ 'whereILike',
38
+ 'andWhereILike',
39
+ 'orWhereILike',
36
40
  'whereRaw',
37
41
  'whereWrapped',
38
42
  'havingWrapped',
@@ -691,11 +691,21 @@ class Builder extends EventEmitter {
691
691
  return this._whereLike('whereLike', column, value);
692
692
  }
693
693
 
694
+ // Adds a `or where like` clause to the query.
695
+ orWhereLike(column, value) {
696
+ return this._bool('or')._whereLike('whereLike', column, value);
697
+ }
698
+
694
699
  // Adds a `where ilike` clause to the query.
695
700
  whereILike(column, value) {
696
701
  return this._whereLike('whereILike', column, value);
697
702
  }
698
703
 
704
+ // Adds a `or where ilike` clause to the query.
705
+ orWhereILike(column, value) {
706
+ return this._bool('or')._whereLike('whereILike', column, value);
707
+ }
708
+
699
709
  // Adds a `group by` clause to the query.
700
710
  groupBy(item) {
701
711
  if (item && item.isRawInstance) {
@@ -1505,8 +1515,8 @@ class Builder extends EventEmitter {
1505
1515
  return this;
1506
1516
  }
1507
1517
 
1508
- orWhereJsonPath(column, operator, value) {
1509
- return this._bool('or').whereJsonPath(column, operator, value);
1518
+ orWhereJsonPath(column, path, operator, value) {
1519
+ return this._bool('or').whereJsonPath(column, path, operator, value);
1510
1520
  }
1511
1521
 
1512
1522
  // Json superset wheres
@@ -1725,6 +1735,8 @@ Builder.prototype.andWhereNotBetween = Builder.prototype.whereNotBetween;
1725
1735
  Builder.prototype.andWhereJsonObject = Builder.prototype.whereJsonObject;
1726
1736
  Builder.prototype.andWhereNotJsonObject = Builder.prototype.whereJsonObject;
1727
1737
  Builder.prototype.andWhereJsonPath = Builder.prototype.whereJsonPath;
1738
+ Builder.prototype.andWhereLike = Builder.prototype.whereLike;
1739
+ Builder.prototype.andWhereILike = Builder.prototype.whereILike;
1728
1740
  Builder.prototype.andHaving = Builder.prototype.having;
1729
1741
  Builder.prototype.andHavingIn = Builder.prototype.havingIn;
1730
1742
  Builder.prototype.andHavingNotIn = Builder.prototype.havingNotIn;
@@ -124,8 +124,36 @@ class QueryCompiler {
124
124
  select() {
125
125
  let sql = this.with();
126
126
 
127
- const statements = components.map((component) => this[component](this));
128
- sql += compact(statements).join(' ');
127
+ let unionStatement = '';
128
+ // Compute all statements to main query
129
+ const statements = components.map((component) => {
130
+ const statement = this[component](this);
131
+ // We store the 'union' statement to append it at the end.
132
+ // We still need to call the component sequentially because of
133
+ // order of bindings.
134
+ if (component === 'union') {
135
+ unionStatement = statement;
136
+ } else {
137
+ return statement;
138
+ }
139
+ });
140
+
141
+ // Check if we need to wrap the main query.
142
+ // We need to wrap main query if one of union have wrap options to true
143
+ // to avoid error syntax (in PostgreSQL for example).
144
+ const wrapMainQuery =
145
+ this.grouped.union &&
146
+ this.grouped.union.map((u) => u.wrap).some((u) => u);
147
+ const allStatements =
148
+ (wrapMainQuery ? '(' : '') +
149
+ compact(statements).join(' ') +
150
+ (wrapMainQuery ? ')' : '');
151
+
152
+ if (this.onlyUnions()) {
153
+ sql += unionStatement + ' ' + allStatements;
154
+ } else {
155
+ sql += allStatements + (unionStatement ? ' ' + unionStatement : '');
156
+ }
129
157
  return sql;
130
158
  }
131
159
 
@@ -706,9 +734,10 @@ class QueryCompiler {
706
734
  this.bindingsHolder
707
735
  );
708
736
  if (statement) {
709
- if (union.wrap) sql += '(';
737
+ const wrap = union.wrap;
738
+ if (wrap) sql += '(';
710
739
  sql += statement;
711
- if (union.wrap) sql += ')';
740
+ if (wrap) sql += ')';
712
741
  }
713
742
  }
714
743
  return sql;
@@ -842,6 +871,7 @@ class QueryCompiler {
842
871
  }
843
872
 
844
873
  onBasic(clause) {
874
+ const toWrap = clause.value instanceof QueryBuilder;
845
875
  return (
846
876
  wrap_(
847
877
  clause.column,
@@ -858,13 +888,15 @@ class QueryCompiler {
858
888
  this.bindingsHolder
859
889
  ) +
860
890
  ' ' +
891
+ (toWrap ? '(' : '') +
861
892
  wrap_(
862
893
  clause.value,
863
894
  undefined,
864
895
  this.builder,
865
896
  this.client,
866
897
  this.bindingsHolder
867
- )
898
+ ) +
899
+ (toWrap ? ')' : '')
868
900
  );
869
901
  }
870
902
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knex",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A batteries-included SQL query & schema builder for PostgresSQL, MySQL, CockroachDB, MSSQL and SQLite3",
5
5
  "main": "knex",
6
6
  "types": "types/index.d.ts",
@@ -114,7 +114,7 @@
114
114
  "husky": "^4.3.8",
115
115
  "jake": "^8.1.1",
116
116
  "JSONStream": "^1.3.5",
117
- "lint-staged": "^11.1.2",
117
+ "lint-staged": "^12.3.4",
118
118
  "mocha": "^9.2.0",
119
119
  "mock-fs": "^5.1.2",
120
120
  "mysql": "^2.18.1",
@@ -123,7 +123,7 @@
123
123
  "oracledb": "^5.3.0",
124
124
  "pg": "^8.7.1",
125
125
  "pg-query-stream": "^4.2.1",
126
- "prettier": "2.4.1",
126
+ "prettier": "2.5.1",
127
127
  "rimraf": "^3.0.2",
128
128
  "sinon": "^13.0.1",
129
129
  "sinon-chai": "^3.7.0",
@@ -146,7 +146,7 @@
146
146
  "type": "git",
147
147
  "url": "git://github.com/knex/knex.git"
148
148
  },
149
- "homepage": "https://knexjs.org",
149
+ "homepage": "https://knex.github.io/documentation/",
150
150
  "keywords": [
151
151
  "sql",
152
152
  "query",
@@ -175,6 +175,9 @@
175
175
  "name": "Igor Savin",
176
176
  "web": "https://www.codeflashbacks.com"
177
177
  },
178
+ {
179
+ "name": "Olivier Cavadenti"
180
+ },
178
181
  {
179
182
  "name": "Simon Liden"
180
183
  },
@@ -185,9 +188,6 @@
185
188
  {
186
189
  "name": "Brian Lauber",
187
190
  "web": "https://briandamaged.org"
188
- },
189
- {
190
- "name": "Olivier Cavadenti"
191
191
  }
192
192
  ],
193
193
  "browser": {
package/types/index.d.ts CHANGED
@@ -284,27 +284,6 @@ type AggregationQueryResult<TResult, TIntersectProps2> = ArrayIfAlready<
284
284
  : TIntersectProps2
285
285
  >;
286
286
 
287
- // Convenience alias and associated companion namespace for working
288
- // with DeferredSelection having TSingle=true.
289
- //
290
- // When TSingle=true in DeferredSelection, then we are effectively
291
- // deferring an index access operation (TBase[TKey]) over a potentially
292
- // unknown initial type of TBase and potentially never initial type of TKey
293
-
294
- type DeferredIndex<TBase, TKey extends string> = DeferredKeySelection<TBase, TKey, false, {}, true>;
295
-
296
- declare namespace DeferredIndex {
297
- type Augment<
298
- T,
299
- TBase,
300
- TKey extends string,
301
- TAliasMapping = {}
302
- > = DeferredKeySelection.SetSingle<
303
- DeferredKeySelection.AddKey<DeferredKeySelection.SetBase<T, TBase>, TKey>,
304
- true
305
- >;
306
- }
307
-
308
287
  // If we have more categories of deferred selection in future,
309
288
  // this will combine all of them
310
289
  type ResolveResult<S> = DeferredKeySelection.Resolve<S>;
@@ -548,7 +527,11 @@ export declare namespace Knex {
548
527
  whereNotIn: WhereIn<TRecord, TResult>;
549
528
  orWhereNotIn: WhereIn<TRecord, TResult>;
550
529
  whereLike: Where<TRecord, TResult>;
530
+ andWhereLike: Where<TRecord, TResult>;
531
+ orWhereLike: Where<TRecord, TResult>;
551
532
  whereILike: Where<TRecord, TResult>;
533
+ andWhereILike: Where<TRecord, TResult>;
534
+ orWhereILike: Where<TRecord, TResult>;
552
535
  whereNull: WhereNull<TRecord, TResult>;
553
536
  orWhereNull: WhereNull<TRecord, TResult>;
554
537
  whereNotNull: WhereNull<TRecord, TResult>;
@@ -694,7 +677,7 @@ export declare namespace Knex {
694
677
  ): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
695
678
  insert<
696
679
  TKey extends StrKey<ResolveTableType<TRecord>>,
697
- TResult2 = DeferredIndex.Augment<
680
+ TResult2 = DeferredKeySelection.Augment<
698
681
  UnwrapArrayMember<TResult>,
699
682
  ResolveTableType<TRecord>,
700
683
  TKey
@@ -722,7 +705,7 @@ export declare namespace Knex {
722
705
  ): QueryBuilder<TRecord, TResult2>;
723
706
  insert<
724
707
  TKey extends string,
725
- TResult2 = DeferredIndex.Augment<
708
+ TResult2 = DeferredKeySelection.Augment<
726
709
  UnwrapArrayMember<TResult>,
727
710
  TRecord,
728
711
  TKey
@@ -736,7 +719,7 @@ export declare namespace Knex {
736
719
  ): QueryBuilder<TRecord, TResult2>;
737
720
  insert<
738
721
  TKey extends string,
739
- TResult2 = DeferredIndex.Augment<
722
+ TResult2 = DeferredKeySelection.Augment<
740
723
  UnwrapArrayMember<TResult>,
741
724
  TRecord,
742
725
  TKey
@@ -763,7 +746,7 @@ export declare namespace Knex {
763
746
  ): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
764
747
  upsert<
765
748
  TKey extends StrKey<ResolveTableType<TRecord>>,
766
- TResult2 = DeferredIndex.Augment<
749
+ TResult2 = DeferredKeySelection.Augment<
767
750
  UnwrapArrayMember<TResult>,
768
751
  ResolveTableType<TRecord>,
769
752
  TKey
@@ -791,7 +774,7 @@ export declare namespace Knex {
791
774
  ): QueryBuilder<TRecord, TResult2>;
792
775
  upsert<
793
776
  TKey extends string,
794
- TResult2 = DeferredIndex.Augment<
777
+ TResult2 = DeferredKeySelection.Augment<
795
778
  UnwrapArrayMember<TResult>,
796
779
  TRecord,
797
780
  TKey
@@ -805,7 +788,7 @@ export declare namespace Knex {
805
788
  ): QueryBuilder<TRecord, TResult2>;
806
789
  upsert<
807
790
  TKey extends string,
808
- TResult2 = DeferredIndex.Augment<
791
+ TResult2 = DeferredKeySelection.Augment<
809
792
  UnwrapArrayMember<TResult>,
810
793
  TRecord,
811
794
  TKey
@@ -830,7 +813,7 @@ export declare namespace Knex {
830
813
  update<
831
814
  K1 extends StrKey<ResolveTableType<TRecord, 'update'>>,
832
815
  K2 extends StrKey<ResolveTableType<TRecord>>,
833
- TResult2 = DeferredIndex.Augment<
816
+ TResult2 = DeferredKeySelection.Augment<
834
817
  UnwrapArrayMember<TResult>,
835
818
  ResolveTableType<TRecord>,
836
819
  K2
@@ -872,7 +855,7 @@ export declare namespace Knex {
872
855
  ): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
873
856
  update<
874
857
  TKey extends StrKey<ResolveTableType<TRecord>>,
875
- TResult2 = DeferredIndex.Augment<
858
+ TResult2 = DeferredKeySelection.Augment<
876
859
  UnwrapArrayMember<TResult>,
877
860
  ResolveTableType<TRecord>,
878
861
  TKey
@@ -927,7 +910,7 @@ export declare namespace Knex {
927
910
  returning(column: '*', options?: DMLOptions): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
928
911
  returning<
929
912
  TKey extends StrKey<ResolveTableType<TRecord>>,
930
- TResult2 = DeferredIndex.Augment<
913
+ TResult2 = DeferredKeySelection.Augment<
931
914
  UnwrapArrayMember<TResult>,
932
915
  ResolveTableType<TRecord>,
933
916
  TKey
@@ -952,24 +935,15 @@ export declare namespace Knex {
952
935
  ): QueryBuilder<TRecord, TResult2>;
953
936
 
954
937
  onConflict<
955
- TKey extends StrKey<ResolveTableType<TRecord>>,
956
- TResult2 = DeferredIndex.Augment<
957
- UnwrapArrayMember<TResult>,
958
- TRecord,
959
- TKey
960
- >[]
938
+ TKey extends StrKey<ResolveTableType<TRecord>>
961
939
  >(
962
940
  column: TKey
963
- ): OnConflictQueryBuilder<TRecord, TResult2>;
941
+ ): OnConflictQueryBuilder<TRecord, TResult>;
964
942
  onConflict<
965
- TKey extends StrKey<ResolveTableType<TRecord>>,
966
- TResult2 = DeferredKeySelection.SetSingle<
967
- DeferredKeySelection.Augment<UnwrapArrayMember<TResult>, TRecord, TKey>,
968
- false
969
- >[]
943
+ TKey extends StrKey<ResolveTableType<TRecord>>
970
944
  >(
971
945
  columns: readonly TKey[]
972
- ): OnConflictQueryBuilder<TRecord, TResult2>;
946
+ ): OnConflictQueryBuilder<TRecord, TResult>;
973
947
 
974
948
  onConflict(
975
949
  columns: string
@@ -991,7 +965,7 @@ export declare namespace Knex {
991
965
  ): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
992
966
  del<
993
967
  TKey extends StrKey<TRecord>,
994
- TResult2 = DeferredIndex.Augment<
968
+ TResult2 = DeferredKeySelection.Augment<
995
969
  UnwrapArrayMember<TResult>,
996
970
  TRecord,
997
971
  TKey
@@ -1023,7 +997,7 @@ export declare namespace Knex {
1023
997
  ): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
1024
998
  delete<
1025
999
  TKey extends StrKey<ResolveTableType<TRecord>>,
1026
- TResult2 = DeferredIndex.Augment<
1000
+ TResult2 = DeferredKeySelection.Augment<
1027
1001
  UnwrapArrayMember<TResult>,
1028
1002
  ResolveTableType<TRecord>,
1029
1003
  TKey
@@ -1833,7 +1807,7 @@ export declare namespace Knex {
1833
1807
  returning(column: '*'): BatchInsertBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
1834
1808
  returning<
1835
1809
  TKey extends StrKey<ResolveTableType<TRecord>>,
1836
- TResult2 = DeferredIndex.Augment<
1810
+ TResult2 = DeferredKeySelection.Augment<
1837
1811
  UnwrapArrayMember<TResult>,
1838
1812
  ResolveTableType<TRecord>,
1839
1813
  TKey
@@ -2031,7 +2005,7 @@ export declare namespace Knex {
2031
2005
  createTableLike(
2032
2006
  tableName: string,
2033
2007
  tableNameLike: string,
2034
- callback: (tableBuilder: CreateTableBuilder) => any
2008
+ callback?: (tableBuilder: CreateTableBuilder) => any
2035
2009
  ): SchemaBuilder;
2036
2010
  alterTable(
2037
2011
  tableName: string,