knex 0.95.12-rc4 → 0.95.13

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,44 @@
1
1
  # Master (Unreleased)
2
2
 
3
+ # 0.95.13 - 02 November, 2021
4
+
5
+ ### Bug fixes:
6
+
7
+ - PostgreSQL: Support zero precision in timestamp/datetime #4784
8
+
9
+ ### Typings:
10
+
11
+ - Allow string indexType in index creation #4791
12
+
13
+ # 0.95.12 - 28 October, 2021
14
+
15
+ ### New features:
16
+
17
+ - New dialect: CockroachDB #4742
18
+ - New dialect: pg-native #4327
19
+ - CockroachDB: add support for upsert #4767
20
+ - PostgreSQL: Support SELECT .. FOR NO KEY UPDATE / KEY SHARE row level locking clauses #4755
21
+ - PostgreSQL: Add support for 'CASCADE' in PostgreSQL 'DROP SCHEMA' queries #4713
22
+ - MySQL: Add storage engine index Type support to index() and unique() schema #4756
23
+ - MSSQL: Support table.primary, table.unique variant with options object #4710
24
+ - SQLite: Add setNullable support to SQLite #4684
25
+ - Add geometry column building #4776
26
+ - Add support for creating table copies #1373
27
+ - Implement support for views and materialized views #1626
28
+ - Implement partial index support #4768
29
+ - Support for 'is null' in 'order by' #3667
30
+
31
+ ### Bug fixes:
32
+
33
+ - Fix support for Oracle connections passed via knex.connection() #4757
34
+ - Avoid inserting multiple locks if a migration lock already exists #4694
35
+
36
+ ### Typings:
37
+
38
+ - Some TableBuilder methods return wrong types #4764
39
+ - Update JoinRaw bindings type to accept arrays #4752
40
+ - fix onDelete/onUpdate for ColumnBuilder #4656
41
+
3
42
  # 0.95.11 - 03 September, 2021
4
43
 
5
44
  ### New features:
@@ -0,0 +1,11 @@
1
+ const QueryBuilder = require('../../query/querybuilder');
2
+ const isEmpty = require('lodash/isEmpty');
3
+
4
+ module.exports = class QueryBuilder_CockroachDB extends QueryBuilder {
5
+ upsert(values, returning, options) {
6
+ this._method = 'upsert';
7
+ if (!isEmpty(returning)) this.returning(returning, options);
8
+ this._single.upsert = values;
9
+ return this;
10
+ }
11
+ };
@@ -1,9 +1,63 @@
1
1
  const QueryCompiler_PG = require('../postgres/query/pg-querycompiler');
2
+ const isEmpty = require('lodash/isEmpty');
3
+ const { columnize: columnize_ } = require('../../formatter/wrappingFormatter');
2
4
 
3
5
  class QueryCompiler_CRDB extends QueryCompiler_PG {
4
6
  truncate() {
5
7
  return `truncate ${this.tableName}`;
6
8
  }
9
+
10
+ upsert() {
11
+ let sql = this._upsert();
12
+ if (sql === '') return sql;
13
+ const { returning } = this.single;
14
+ if (returning) sql += this._returning(returning);
15
+ return {
16
+ sql: sql,
17
+ returning,
18
+ };
19
+ }
20
+
21
+ _upsert() {
22
+ const upsertValues = this.single.upsert || [];
23
+ let sql = this.with() + `upsert into ${this.tableName} `;
24
+ if (Array.isArray(upsertValues)) {
25
+ if (upsertValues.length === 0) return '';
26
+ } else if (typeof upsertValues === 'object' && isEmpty(upsertValues)) {
27
+ return sql + this._emptyInsertValue;
28
+ }
29
+
30
+ const upsertData = this._prepInsert(upsertValues);
31
+ if (typeof upsertData === 'string') {
32
+ sql += upsertData;
33
+ } else {
34
+ if (upsertData.columns.length) {
35
+ sql += `(${columnize_(
36
+ upsertData.columns,
37
+ this.builder,
38
+ this.client,
39
+ this.bindingsHolder
40
+ )}`;
41
+ sql += ') values (';
42
+ let i = -1;
43
+ while (++i < upsertData.values.length) {
44
+ if (i !== 0) sql += '), (';
45
+ sql += this.client.parameterize(
46
+ upsertData.values[i],
47
+ this.client.valueForUndefined,
48
+ this.builder,
49
+ this.bindingsHolder
50
+ );
51
+ }
52
+ sql += ')';
53
+ } else if (upsertValues.length === 1 && upsertValues[0]) {
54
+ sql += this._emptyInsertValue;
55
+ } else {
56
+ sql = '';
57
+ }
58
+ }
59
+ return sql;
60
+ }
7
61
  }
8
62
 
9
63
  module.exports = QueryCompiler_CRDB;
@@ -5,6 +5,7 @@ const Transaction = require('../postgres/execution/pg-transaction');
5
5
  const QueryCompiler = require('./crdb-querycompiler');
6
6
  const TableCompiler = require('./crdb-tablecompiler');
7
7
  const ViewCompiler = require('./crdb-viewcompiler');
8
+ const QueryBuilder = require('./crdb-querybuilder');
8
9
 
9
10
  // Always initialize with the "QueryBuilder" and "QueryCompiler"
10
11
  // objects, which extend the base 'lib/query/builder' and
@@ -26,6 +27,10 @@ class Client_CockroachDB extends Client_PostgreSQL {
26
27
  return new ViewCompiler(this, ...arguments);
27
28
  }
28
29
 
30
+ queryBuilder() {
31
+ return new QueryBuilder(this);
32
+ }
33
+
29
34
  _parseVersion(versionString) {
30
35
  return versionString.split(' ')[2];
31
36
  }
@@ -219,14 +219,22 @@ class TableCompiler_MSSQL extends TableCompiler {
219
219
  );
220
220
  }
221
221
 
222
- index(columns, indexName) {
222
+ index(columns, indexName, options) {
223
223
  indexName = indexName
224
224
  ? this.formatter.wrap(indexName)
225
225
  : this._indexCommand('index', this.tableNameRaw, columns);
226
+
227
+ let predicate;
228
+ if (isObject(options)) {
229
+ ({ predicate } = options);
230
+ }
231
+ const predicateQuery = predicate
232
+ ? ' ' + this.client.queryCompiler(predicate).where()
233
+ : '';
226
234
  this.pushQuery(
227
235
  `CREATE INDEX ${indexName} ON ${this.tableName()} (${this.formatter.columnize(
228
236
  columns
229
- )})`
237
+ )})${predicateQuery}`
230
238
  );
231
239
  }
232
240
 
@@ -3,7 +3,7 @@
3
3
  // MySQL Table Builder & Compiler
4
4
  // -------
5
5
  const TableCompiler = require('../../../schema/tablecompiler');
6
- const { isObject } = require('../../../util/is');
6
+ const { isObject, isString } = require('../../../util/is');
7
7
 
8
8
  // Table Compiler
9
9
  // ------
@@ -211,14 +211,28 @@ class TableCompiler_MySQL extends TableCompiler {
211
211
  );
212
212
  }
213
213
 
214
- index(columns, indexName, indexType) {
214
+ index(columns, indexName, options) {
215
+ let storageEngineIndexType;
216
+ let indexType;
217
+
218
+ if (isString(options)) {
219
+ indexType = options;
220
+ } else if (isObject(options)) {
221
+ ({ indexType, storageEngineIndexType } = options);
222
+ }
223
+
215
224
  indexName = indexName
216
225
  ? this.formatter.wrap(indexName)
217
226
  : this._indexCommand('index', this.tableNameRaw, columns);
227
+ storageEngineIndexType = storageEngineIndexType
228
+ ? ` using ${storageEngineIndexType}`
229
+ : '';
218
230
  this.pushQuery(
219
231
  `alter table ${this.tableName()} add${
220
232
  indexType ? ` ${indexType}` : ''
221
- } index ${indexName}(${this.formatter.columnize(columns)})`
233
+ } index ${indexName}(${this.formatter.columnize(
234
+ columns
235
+ )})${storageEngineIndexType}`
222
236
  );
223
237
  }
224
238
 
@@ -243,9 +257,10 @@ class TableCompiler_MySQL extends TableCompiler {
243
257
  }
244
258
 
245
259
  unique(columns, indexName) {
260
+ let storageEngineIndexType;
246
261
  let deferrable;
247
262
  if (isObject(indexName)) {
248
- ({ indexName, deferrable } = indexName);
263
+ ({ indexName, deferrable, storageEngineIndexType } = indexName);
249
264
  }
250
265
  if (deferrable && deferrable !== 'not deferrable') {
251
266
  this.client.logger.warn(
@@ -255,10 +270,13 @@ class TableCompiler_MySQL extends TableCompiler {
255
270
  indexName = indexName
256
271
  ? this.formatter.wrap(indexName)
257
272
  : this._indexCommand('unique', this.tableNameRaw, columns);
273
+ storageEngineIndexType = storageEngineIndexType
274
+ ? ` using ${storageEngineIndexType}`
275
+ : '';
258
276
  this.pushQuery(
259
277
  `alter table ${this.tableName()} add unique ${indexName}(${this.formatter.columnize(
260
278
  columns
261
- )})`
279
+ )})${storageEngineIndexType}`
262
280
  );
263
281
  }
264
282
 
@@ -147,20 +147,26 @@ class QueryCompiler_PG extends QueryCompiler {
147
147
  return sql.join(', ');
148
148
  }
149
149
 
150
- forUpdate() {
150
+ _lockingClause(lockMode) {
151
151
  const tables = this.single.lockTables || [];
152
152
 
153
- return (
154
- 'for update' + (tables.length ? ' of ' + this._tableNames(tables) : '')
155
- );
153
+ return lockMode + (tables.length ? ' of ' + this._tableNames(tables) : '');
154
+ }
155
+
156
+ forUpdate() {
157
+ return this._lockingClause('for update');
156
158
  }
157
159
 
158
160
  forShare() {
159
- const tables = this.single.lockTables || [];
161
+ return this._lockingClause('for share');
162
+ }
163
+
164
+ forNoKeyUpdate() {
165
+ return this._lockingClause('for no key update');
166
+ }
160
167
 
161
- return (
162
- 'for share' + (tables.length ? ' of ' + this._tableNames(tables) : '')
163
- );
168
+ forKeyShare() {
169
+ return this._lockingClause('for key share');
164
170
  }
165
171
 
166
172
  skipLocked() {
@@ -72,22 +72,16 @@ class ColumnCompiler_PG extends ColumnCompiler {
72
72
  useTz = !withoutTz;
73
73
  }
74
74
  useTz = typeof useTz === 'boolean' ? useTz : true;
75
- precision = precision ? '(' + precision + ')' : '';
75
+ precision =
76
+ precision !== undefined && precision !== null
77
+ ? '(' + precision + ')'
78
+ : '';
76
79
 
77
80
  return `${useTz ? 'timestamptz' : 'timestamp'}${precision}`;
78
81
  }
79
82
 
80
83
  timestamp(withoutTz = false, precision) {
81
- let useTz;
82
- if (isObject(withoutTz)) {
83
- ({ useTz, precision } = withoutTz);
84
- } else {
85
- useTz = !withoutTz;
86
- }
87
- useTz = typeof useTz === 'boolean' ? useTz : true;
88
- precision = precision ? '(' + precision + ')' : '';
89
-
90
- return `${useTz ? 'timestamptz' : 'timestamp'}${precision}`;
84
+ return this.datetime(withoutTz, precision);
91
85
  }
92
86
 
93
87
  // Modifiers:
@@ -5,7 +5,7 @@
5
5
 
6
6
  const has = require('lodash/has');
7
7
  const TableCompiler = require('../../../schema/tablecompiler');
8
- const { isObject } = require('../../../util/is');
8
+ const { isObject, isString } = require('../../../util/is');
9
9
 
10
10
  class TableCompiler_PG extends TableCompiler {
11
11
  constructor(client, tableBuilder) {
@@ -161,17 +161,32 @@ class TableCompiler_PG extends TableCompiler {
161
161
  );
162
162
  }
163
163
 
164
- index(columns, indexName, indexType) {
164
+ index(columns, indexName, options) {
165
165
  indexName = indexName
166
166
  ? this.formatter.wrap(indexName)
167
167
  : this._indexCommand('index', this.tableNameRaw, columns);
168
+
169
+ let predicate;
170
+ let indexType;
171
+
172
+ if (isString(options)) {
173
+ indexType = options;
174
+ } else if (isObject(options)) {
175
+ ({ indexType, predicate } = options);
176
+ }
177
+
178
+ const predicateQuery = predicate
179
+ ? ' ' + this.client.queryCompiler(predicate).where()
180
+ : '';
181
+
168
182
  this.pushQuery(
169
183
  `create index ${indexName} on ${this.tableName()}${
170
184
  (indexType && ` using ${indexType}`) || ''
171
185
  }` +
172
186
  ' (' +
173
187
  this.formatter.columnize(columns) +
174
- ')'
188
+ ')' +
189
+ `${predicateQuery}`
175
190
  );
176
191
  }
177
192
 
@@ -61,6 +61,18 @@ class QueryCompiler_Redshift extends QueryCompiler_PG {
61
61
  return '';
62
62
  }
63
63
 
64
+ forNoKeyUpdate() {
65
+ this.client.logger.warn('table lock is not supported by redshift dialect');
66
+ return '';
67
+ }
68
+
69
+ forKeyShare() {
70
+ this.client.logger.warn(
71
+ 'lock for share is not supported by redshift dialect'
72
+ );
73
+ return '';
74
+ }
75
+
64
76
  // Compiles a columnInfo query
65
77
  columnInfo() {
66
78
  const column = this.single.columnInfo;
@@ -11,7 +11,7 @@ class TableCompiler_Redshift extends TableCompiler_PG {
11
11
  super(...arguments);
12
12
  }
13
13
 
14
- index(columns, indexName, indexType) {
14
+ index(columns, indexName, options) {
15
15
  this.client.logger.warn(
16
16
  'Redshift does not support the creation of indexes.'
17
17
  );
@@ -27,7 +27,9 @@ class QueryCompiler_SQLite3 extends QueryCompiler {
27
27
 
28
28
  // The locks are not applicable in SQLite3
29
29
  this.forShare = emptyStr;
30
+ this.forKeyShare = emptyStr;
30
31
  this.forUpdate = emptyStr;
32
+ this.forNoKeyUpdate = emptyStr;
31
33
  }
32
34
 
33
35
  // SQLite requires us to build the multi-row insert as a listing of select with
@@ -145,13 +145,21 @@ class TableCompiler_SQLite3 extends TableCompiler {
145
145
  }
146
146
 
147
147
  // Compile a plain index key command.
148
- index(columns, indexName) {
148
+ index(columns, indexName, options) {
149
149
  indexName = indexName
150
150
  ? this.formatter.wrap(indexName)
151
151
  : this._indexCommand('index', this.tableNameRaw, columns);
152
152
  columns = this.formatter.columnize(columns);
153
+
154
+ let predicate;
155
+ if (isObject(options)) {
156
+ ({ predicate } = options);
157
+ }
158
+ const predicateQuery = predicate
159
+ ? ' ' + this.client.queryCompiler(predicate).where()
160
+ : '';
153
161
  this.pushQuery(
154
- `create index ${indexName} on ${this.tableName()} (${columns})`
162
+ `create index ${indexName} on ${this.tableName()} (${columns})${predicateQuery}`
155
163
  );
156
164
  }
157
165
 
@@ -5,6 +5,8 @@ module.exports = {
5
5
  lockMode: {
6
6
  forShare: 'forShare',
7
7
  forUpdate: 'forUpdate',
8
+ forNoKeyUpdate: 'forNoKeyUpdate',
9
+ forKeyShare: 'forKeyShare',
8
10
  },
9
11
  waitMode: {
10
12
  skipLocked: 'skipLocked',
@@ -46,7 +46,12 @@ const CLEARABLE_STATEMENTS = new Set([
46
46
  'counter',
47
47
  'counters',
48
48
  ]);
49
- const LOCK_MODES = new Set([lockMode.forShare, lockMode.forUpdate]);
49
+ const LOCK_MODES = new Set([
50
+ lockMode.forShare,
51
+ lockMode.forUpdate,
52
+ lockMode.forNoKeyUpdate,
53
+ lockMode.forKeyShare,
54
+ ]);
50
55
 
51
56
  // Typically called from `knex.builder`,
52
57
  // start a new query building chain.
@@ -1198,6 +1203,20 @@ class Builder extends EventEmitter {
1198
1203
  return this;
1199
1204
  }
1200
1205
 
1206
+ // Set a lock for no key update constraint.
1207
+ forNoKeyUpdate(...tables) {
1208
+ this._single.lock = lockMode.forNoKeyUpdate;
1209
+ this._single.lockTables = tables;
1210
+ return this;
1211
+ }
1212
+
1213
+ // Set a lock for key share constraint.
1214
+ forKeyShare(...tables) {
1215
+ this._single.lock = lockMode.forKeyShare;
1216
+ this._single.lockTables = tables;
1217
+ return this;
1218
+ }
1219
+
1201
1220
  // Skips locked rows when using a lock constraint.
1202
1221
  skipLocked() {
1203
1222
  if (!this._isSelectQuery()) {
@@ -1254,6 +1273,12 @@ class Builder extends EventEmitter {
1254
1273
  return this;
1255
1274
  }
1256
1275
 
1276
+ upsert(values, returning, options) {
1277
+ throw new Error(
1278
+ `Upsert is not yet supported for dialect ${this.client.dialect}`
1279
+ );
1280
+ }
1281
+
1257
1282
  _analytic(alias, second, third) {
1258
1283
  let analytic;
1259
1284
  const { schema } = this._single;
@@ -142,6 +142,9 @@ ColumnCompiler.prototype.date = 'date';
142
142
  ColumnCompiler.prototype.datetime = 'datetime';
143
143
  ColumnCompiler.prototype.time = 'time';
144
144
  ColumnCompiler.prototype.timestamp = 'timestamp';
145
+ ColumnCompiler.prototype.geometry = 'geometry';
146
+ ColumnCompiler.prototype.geography = 'geography';
147
+ ColumnCompiler.prototype.point = 'point';
145
148
  ColumnCompiler.prototype.enu = 'varchar';
146
149
  ColumnCompiler.prototype.bit = ColumnCompiler.prototype.json = 'text';
147
150
  ColumnCompiler.prototype.uuid = 'char(36)';
@@ -218,6 +218,11 @@ const columnTypes = [
218
218
  'time',
219
219
  'year',
220
220
 
221
+ // Geometry
222
+ 'geometry',
223
+ 'geography',
224
+ 'point',
225
+
221
226
  // String
222
227
  'char',
223
228
  'varchar',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knex",
3
- "version": "0.95.12-rc4",
3
+ "version": "0.95.13",
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",
@@ -17,7 +17,7 @@
17
17
  "lint:everything": "npm run lint:types && npm run lint",
18
18
  "test:unit": "npm run test:unit-only && npm run test:cli",
19
19
  "test:unit-only": "mocha --exit -t 10000 --config test/mocha-unit-config-test.js",
20
- "test:db": "mocha --exit -t 10000 --config test/mocha-integration-config-test.js && npm run test:tape",
20
+ "test:db": "mocha --exit -t 10000 --config test/mocha-integration-config-test.js",
21
21
  "test:db:coverage": "nyc mocha --exit --check-leaks -t 10000 --config test/mocha-integration-config-test.js && npm run test:tape",
22
22
  "test:db:no-oracle": "cross-env DB=\"mssql mysql mysql2 postgres sqlite3\" mocha --exit -t 10000 --config test/mocha-integration-config-test.js && npm run test:tape",
23
23
  "test": "mocha --exit -t 10000 --config test/mocha-all-config-test.js && npm run test:tape && npm run test:cli",
@@ -33,8 +33,8 @@
33
33
  "test:pgnative": "cross-env DB=pgnative npm run test:db",
34
34
  "test:tape": "node test/tape/index.js | tap-spec",
35
35
  "test:cli": "cross-env KNEX_PATH=../knex.js KNEX=bin/cli.js jake -f test/jake/Jakefile",
36
- "db:start": "docker-compose -f scripts/docker-compose.yml up --build -d mysql oracledbxe postgres mssql && docker-compose -f scripts/docker-compose.yml up waitmssql waitmysql waitpostgres waitoracledbxe",
37
- "db:start:no-oracle": "docker-compose -f scripts/docker-compose.yml up --build -d mysql postgres mssql && docker-compose -f scripts/docker-compose.yml up waitmssql waitmysql waitpostgres",
36
+ "db:start": "docker-compose -f scripts/docker-compose.yml up --build -d mysql oracledbxe postgres mssql cockroachdb pgnative && docker-compose -f scripts/docker-compose.yml up waitmssql waitmysql waitpostgres waitoracledbxe",
37
+ "db:start:no-oracle": "docker-compose -f scripts/docker-compose.yml up --build -d mysql postgres mssql cockroachdb pgnative && docker-compose -f scripts/docker-compose.yml up waitmssql waitmysql waitpostgres",
38
38
  "db:stop": "docker-compose -f scripts/docker-compose.yml down",
39
39
  "db:start:postgres": "docker-compose -f scripts/docker-compose.yml up --build -d postgres && docker-compose -f scripts/docker-compose.yml up waitpostgres",
40
40
  "db:stop:postgres": "docker-compose -f scripts/docker-compose.yml down",
@@ -101,10 +101,10 @@
101
101
  "cli-testlab": "^2.2.0",
102
102
  "coveralls": "^3.1.1",
103
103
  "cross-env": "^7.0.3",
104
- "dtslint": "4.1.6",
105
- "eslint": "^7.32.0",
104
+ "dtslint": "4.2.0",
105
+ "eslint": "^8.1.0",
106
106
  "eslint-config-prettier": "^8.3.0",
107
- "eslint-plugin-import": "^2.24.2",
107
+ "eslint-plugin-import": "^2.25.2",
108
108
  "husky": "^4.3.8",
109
109
  "jake": "^8.1.1",
110
110
  "JSONStream": "^1.3.5",
@@ -128,8 +128,8 @@
128
128
  "tedious": "^12.2.0",
129
129
  "toxiproxy-node-client": "^2.0.6",
130
130
  "ts-node": "^10.2.1",
131
- "tsd": "^0.17.0",
132
- "typescript": "4.4.3"
131
+ "tsd": "^0.18.0",
132
+ "typescript": "4.4.4"
133
133
  },
134
134
  "buildDependencies": [
135
135
  "rimraf"
@@ -2,7 +2,7 @@ version: '3'
2
2
 
3
3
  services:
4
4
  mssql:
5
- image: mcr.microsoft.com/mssql/server:2017-latest
5
+ image: mcr.microsoft.com/mssql/server:2019-latest
6
6
  ports:
7
7
  - '21433:1433'
8
8
  environment:
package/types/index.d.ts CHANGED
@@ -456,10 +456,11 @@ export declare namespace Knex {
456
456
 
457
457
  type DbRecordArr<TRecord> = Readonly<MaybeArray<DbRecord<TRecord>>>;
458
458
 
459
- export type CompositeTableType<TBase, TInsert = TBase, TUpdate = Partial<TInsert>> = {
459
+ export type CompositeTableType<TBase, TInsert = TBase, TUpdate = Partial<TInsert>, TUpsert = Partial<TInsert>> = {
460
460
  base: TBase,
461
461
  insert: TInsert,
462
462
  update: TUpdate,
463
+ upsert: TUpsert,
463
464
  };
464
465
 
465
466
  type TableNames = keyof Tables;
@@ -714,6 +715,75 @@ export declare namespace Knex {
714
715
  : DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>
715
716
  ): QueryBuilder<TRecord, TResult2>;
716
717
 
718
+ upsert(
719
+ data: TRecord extends CompositeTableType<unknown>
720
+ ? ResolveTableType<TRecord, 'upsert'> | ReadonlyArray<ResolveTableType<TRecord, 'upsert'>>
721
+ : DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
722
+ returning: '*',
723
+ options?: DMLOptions
724
+ ): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
725
+ upsert<
726
+ TKey extends StrKey<ResolveTableType<TRecord>>,
727
+ TResult2 = DeferredIndex.Augment<
728
+ UnwrapArrayMember<TResult>,
729
+ ResolveTableType<TRecord>,
730
+ TKey
731
+ >[]
732
+ >(
733
+ data: TRecord extends CompositeTableType<unknown>
734
+ ? ResolveTableType<TRecord, 'upsert'> | ReadonlyArray<ResolveTableType<TRecord, 'upsert'>>
735
+ : DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
736
+ returning: TKey,
737
+ options?: DMLOptions
738
+ ): QueryBuilder<TRecord, TResult2>;
739
+ upsert<
740
+ TKey extends StrKey<ResolveTableType<TRecord>>,
741
+ TResult2 = DeferredKeySelection.Augment<
742
+ UnwrapArrayMember<TResult>,
743
+ ResolveTableType<TRecord>,
744
+ TKey
745
+ >[]
746
+ >(
747
+ data: TRecord extends CompositeTableType<unknown>
748
+ ? ResolveTableType<TRecord, 'upsert'> | ReadonlyArray<ResolveTableType<TRecord, 'upsert'>>
749
+ : DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
750
+ returning: readonly TKey[],
751
+ options?: DMLOptions
752
+ ): QueryBuilder<TRecord, TResult2>;
753
+ upsert<
754
+ TKey extends string,
755
+ TResult2 = DeferredIndex.Augment<
756
+ UnwrapArrayMember<TResult>,
757
+ TRecord,
758
+ TKey
759
+ >[]
760
+ >(
761
+ data: TRecord extends CompositeTableType<unknown>
762
+ ? ResolveTableType<TRecord, 'upsert'> | ReadonlyArray<ResolveTableType<TRecord, 'upsert'>>
763
+ : DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
764
+ returning: TKey,
765
+ options?: DMLOptions
766
+ ): QueryBuilder<TRecord, TResult2>;
767
+ upsert<
768
+ TKey extends string,
769
+ TResult2 = DeferredIndex.Augment<
770
+ UnwrapArrayMember<TResult>,
771
+ TRecord,
772
+ TKey
773
+ >[]
774
+ >(
775
+ data: TRecord extends CompositeTableType<unknown>
776
+ ? ResolveTableType<TRecord, 'upsert'> | ReadonlyArray<ResolveTableType<TRecord, 'upsert'>>
777
+ : DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
778
+ returning: readonly TKey[],
779
+ options?: DMLOptions
780
+ ): QueryBuilder<TRecord, TResult2>;
781
+ upsert<TResult2 = number[]>(
782
+ data: TRecord extends CompositeTableType<unknown>
783
+ ? ResolveTableType<TRecord, 'upsert'> | ReadonlyArray<ResolveTableType<TRecord, 'upsert'>>
784
+ : DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>
785
+ ): QueryBuilder<TRecord, TResult2>;
786
+
717
787
  modify<TRecord2 extends {} = any, TResult2 extends {} = any>(
718
788
  callback: QueryCallbackWithArgs<TRecord, any>,
719
789
  ...args: any[]
@@ -1740,6 +1810,12 @@ export declare namespace Knex {
1740
1810
  forShare(...tableNames: string[]): QueryBuilder<TRecord, TResult>;
1741
1811
  forShare(tableNames: readonly string[]): QueryBuilder<TRecord, TResult>;
1742
1812
 
1813
+ forNoKeyUpdate(...tableNames: string[]): QueryBuilder<TRecord, TResult>;
1814
+ forNoKeyUpdate(tableNames: readonly string[]): QueryBuilder<TRecord, TResult>;
1815
+
1816
+ forKeyShare(...tableNames: string[]): QueryBuilder<TRecord, TResult>;
1817
+ forKeyShare(tableNames: readonly string[]): QueryBuilder<TRecord, TResult>;
1818
+
1743
1819
  skipLocked(): QueryBuilder<TRecord, TResult>;
1744
1820
  noWait(): QueryBuilder<TRecord, TResult>;
1745
1821
 
@@ -1914,7 +1990,7 @@ export declare namespace Knex {
1914
1990
  ): ColumnBuilder;
1915
1991
  dropColumn(columnName: string): TableBuilder;
1916
1992
  dropColumns(...columnNames: string[]): TableBuilder;
1917
- renameColumn(from: string, to: string): ColumnBuilder;
1993
+ renameColumn(from: string, to: string): TableBuilder;
1918
1994
  integer(columnName: string, length?: number): ColumnBuilder;
1919
1995
  tinyint(columnName: string, length?: number): ColumnBuilder;
1920
1996
  bigInteger(columnName: string): ColumnBuilder;
@@ -1946,7 +2022,10 @@ export declare namespace Knex {
1946
2022
  timestamps(
1947
2023
  useTimestampType?: boolean,
1948
2024
  makeDefaultNow?: boolean
1949
- ): ColumnBuilder;
2025
+ ): void;
2026
+ geometry(columnName: string): ColumnBuilder;
2027
+ geography(columnName: string): ColumnBuilder;
2028
+ point(columnName: string): ColumnBuilder;
1950
2029
  binary(columnName: string, length?: number): ColumnBuilder;
1951
2030
  enum(
1952
2031
  columnName: string,
@@ -1961,7 +2040,7 @@ export declare namespace Knex {
1961
2040
  json(columnName: string): ColumnBuilder;
1962
2041
  jsonb(columnName: string): ColumnBuilder;
1963
2042
  uuid(columnName: string): ColumnBuilder;
1964
- comment(val: string): TableBuilder;
2043
+ comment(val: string): void;
1965
2044
  specificType(columnName: string, type: string): ColumnBuilder;
1966
2045
  primary(columnNames: readonly string[], options?: Readonly<{constraintName?: string, deferrable?: deferrableType}>): TableBuilder;
1967
2046
  /** @deprecated */
@@ -1971,9 +2050,14 @@ export declare namespace Knex {
1971
2050
  indexName?: string,
1972
2051
  indexType?: string
1973
2052
  ): TableBuilder;
2053
+ index(
2054
+ columnNames: string | readonly (string | Raw)[],
2055
+ indexName?: string,
2056
+ options?: Readonly<{indexType?: string, storageEngineIndexType?: storageEngineIndexType, predicate?: QueryBuilder}>
2057
+ ): TableBuilder;
1974
2058
  setNullable(column: string): TableBuilder;
1975
2059
  dropNullable(column: string): TableBuilder;
1976
- unique(columnNames: readonly (string | Raw)[], options?: Readonly<{indexName?: string, deferrable?: deferrableType}>): TableBuilder;
2060
+ unique(columnNames: readonly (string | Raw)[], options?: Readonly<{indexName?: string, storageEngineIndexType?: string, deferrable?: deferrableType}>): TableBuilder;
1977
2061
  /** @deprecated */
1978
2062
  unique(columnNames: readonly (string | Raw)[], indexName?: string): TableBuilder;
1979
2063
  foreign(column: string, foreignKeyName?: string): ForeignConstraintBuilder;
@@ -1985,7 +2069,7 @@ export declare namespace Knex {
1985
2069
  dropUnique(columnNames: readonly (string | Raw)[], indexName?: string): TableBuilder;
1986
2070
  dropPrimary(constraintName?: string): TableBuilder;
1987
2071
  dropIndex(columnNames: string | readonly (string | Raw)[], indexName?: string): TableBuilder;
1988
- dropTimestamps(): ColumnBuilder;
2072
+ dropTimestamps(): TableBuilder;
1989
2073
  queryContext(context: any): TableBuilder;
1990
2074
  }
1991
2075
 
@@ -2017,6 +2101,8 @@ export declare namespace Knex {
2017
2101
  }
2018
2102
 
2019
2103
  type deferrableType = 'not deferrable' | 'immediate' | 'deferred';
2104
+ type storageEngineIndexType = 'hash' | 'btree';
2105
+
2020
2106
  interface ColumnBuilder {
2021
2107
  index(indexName?: string): ColumnBuilder;
2022
2108
  primary(options?: Readonly<{constraintName?: string, deferrable?: deferrableType}>): ColumnBuilder;
@@ -2046,9 +2132,34 @@ export declare namespace Knex {
2046
2132
  }
2047
2133
 
2048
2134
  interface PostgreSqlColumnBuilder extends ColumnBuilder {
2135
+ index(
2136
+ indexName?: string,
2137
+ options?: Readonly<{indexType?: string, predicate?: QueryBuilder}>
2138
+ ): ColumnBuilder;
2049
2139
  index(indexName?: string, indexType?: string): ColumnBuilder;
2050
2140
  }
2051
2141
 
2142
+ interface SqlLiteColumnBuilder extends ColumnBuilder {
2143
+ index(
2144
+ indexName?: string,
2145
+ options?: Readonly<{predicate?: QueryBuilder}>
2146
+ ): ColumnBuilder;
2147
+ }
2148
+
2149
+ interface MsSqlColumnBuilder extends ColumnBuilder {
2150
+ index(
2151
+ indexName?: string,
2152
+ options?: Readonly<{predicate?: QueryBuilder}>
2153
+ ): ColumnBuilder;
2154
+ }
2155
+
2156
+ interface MySqlColumnBuilder extends ColumnBuilder {
2157
+ index(
2158
+ indexName?: string,
2159
+ options?: Readonly<{indexType?: string, storageEngineIndexType?: storageEngineIndexType}>
2160
+ ): ColumnBuilder;
2161
+ }
2162
+
2052
2163
  // patched ColumnBuilder methods to return ReferencingColumnBuilder with new methods
2053
2164
  // relies on ColumnBuilder returning only ColumnBuilder
2054
2165
  type ReferencingColumnBuilder = {