knex 1.0.2 → 1.0.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 +24 -0
- package/lib/dialects/cockroachdb/crdb-querycompiler.js +2 -2
- package/lib/dialects/mysql/schema/mysql-tablecompiler.js +41 -6
- package/lib/dialects/postgres/query/pg-querycompiler.js +3 -3
- package/lib/migrations/seed/stub/js.stub +7 -10
- package/lib/query/method-constants.js +2 -0
- package/package.json +1 -1
- package/types/index.d.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Master (Unreleased)
|
|
2
2
|
|
|
3
|
+
# 1.0.3 - 11 February, 2022
|
|
4
|
+
|
|
5
|
+
### Bug fixes:
|
|
6
|
+
|
|
7
|
+
- Fix error message for missing migration files #4937
|
|
8
|
+
- Add withMaterialized and withNotMaterialized to method-constants #5009
|
|
9
|
+
- PostgreSQL: Fix whereJsonPath queries #5011
|
|
10
|
+
- PostgreSQL: Fix delete joins #5016
|
|
11
|
+
- CockroachDB: Fix whereJsonPath queries #5011
|
|
12
|
+
- MySQL: Create primary keys in same statement #5017
|
|
13
|
+
|
|
14
|
+
### Typings:
|
|
15
|
+
|
|
16
|
+
- Fix type definition for getMigration in MigrationSource #4998
|
|
17
|
+
- Fix argument type of alter method #4996
|
|
18
|
+
|
|
19
|
+
### Improvements:
|
|
20
|
+
|
|
21
|
+
- Use async / await syntax in seeds as default #5005
|
|
22
|
+
|
|
23
|
+
### Documentation:
|
|
24
|
+
|
|
25
|
+
- Add Firebird dialect to ECOSYSTEM.md #5003
|
|
26
|
+
|
|
3
27
|
# 1.0.2 - 02 February, 2022
|
|
4
28
|
|
|
5
29
|
### New features:
|
|
@@ -35,9 +35,9 @@ class QueryCompiler_CRDB extends QueryCompiler_PG {
|
|
|
35
35
|
|
|
36
36
|
whereJsonPath(statement) {
|
|
37
37
|
let castValue = '';
|
|
38
|
-
if (parseInt(statement.value)) {
|
|
38
|
+
if (!isNaN(statement.value) && parseInt(statement.value)) {
|
|
39
39
|
castValue = '::int';
|
|
40
|
-
} else if (parseFloat(statement.value)) {
|
|
40
|
+
} else if (!isNaN(statement.value) && parseFloat(statement.value)) {
|
|
41
41
|
castValue = '::float';
|
|
42
42
|
} else {
|
|
43
43
|
castValue = " #>> '{}'";
|
|
@@ -19,7 +19,12 @@ class TableCompiler_MySQL extends TableCompiler {
|
|
|
19
19
|
: 'create table ';
|
|
20
20
|
const { client } = this;
|
|
21
21
|
let conn = {};
|
|
22
|
-
|
|
22
|
+
let columnsSql = ' (' + columns.sql.join(', ');
|
|
23
|
+
|
|
24
|
+
columnsSql += this.primaryKeys() || '';
|
|
25
|
+
columnsSql += this._addChecks();
|
|
26
|
+
columnsSql += ')';
|
|
27
|
+
|
|
23
28
|
let sql =
|
|
24
29
|
createStatement +
|
|
25
30
|
this.tableName() +
|
|
@@ -135,6 +140,34 @@ class TableCompiler_MySQL extends TableCompiler {
|
|
|
135
140
|
});
|
|
136
141
|
}
|
|
137
142
|
|
|
143
|
+
primaryKeys() {
|
|
144
|
+
const pks = (this.grouped.alterTable || []).filter(
|
|
145
|
+
(k) => k.method === 'primary'
|
|
146
|
+
);
|
|
147
|
+
if (pks.length > 0 && pks[0].args.length > 0) {
|
|
148
|
+
const columns = pks[0].args[0];
|
|
149
|
+
let constraintName = pks[0].args[1] || '';
|
|
150
|
+
if (constraintName) {
|
|
151
|
+
constraintName = ' constraint ' + this.formatter.wrap(constraintName);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (this.grouped.columns) {
|
|
155
|
+
const incrementsCols = this._getIncrementsColumnNames();
|
|
156
|
+
if (incrementsCols.length) {
|
|
157
|
+
incrementsCols.forEach((c) => {
|
|
158
|
+
if (!columns.includes(c)) {
|
|
159
|
+
columns.unshift(c);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return `,${constraintName} primary key (${this.formatter.columnize(
|
|
166
|
+
columns
|
|
167
|
+
)})`;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
138
171
|
getFKRefs(runner) {
|
|
139
172
|
const bindingsHolder = {
|
|
140
173
|
bindings: [],
|
|
@@ -269,11 +302,13 @@ class TableCompiler_MySQL extends TableCompiler {
|
|
|
269
302
|
});
|
|
270
303
|
}
|
|
271
304
|
}
|
|
272
|
-
this.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
305
|
+
if (this.method !== 'create' && this.method !== 'createIfNot') {
|
|
306
|
+
this.pushQuery(
|
|
307
|
+
`alter table ${this.tableName()} add primary key ${constraintName}(${this.formatter.columnize(
|
|
308
|
+
primaryCols
|
|
309
|
+
)})`
|
|
310
|
+
);
|
|
311
|
+
}
|
|
277
312
|
if (incrementsCols.length) {
|
|
278
313
|
this.pushQuery(
|
|
279
314
|
`alter table ${this.tableName()} modify column ${this.formatter.columnize(
|
|
@@ -112,7 +112,7 @@ class QueryCompiler_PG extends QueryCompiler {
|
|
|
112
112
|
);
|
|
113
113
|
}
|
|
114
114
|
if (joinWheres.length > 0) {
|
|
115
|
-
wheres += (wheres ? ' and ' : '') + joinWheres.join(' ');
|
|
115
|
+
wheres += (wheres ? ' and ' : 'where ') + joinWheres.join(' and ');
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
if (tableJoins.length > 0) {
|
|
@@ -341,9 +341,9 @@ class QueryCompiler_PG extends QueryCompiler {
|
|
|
341
341
|
|
|
342
342
|
whereJsonPath(statement) {
|
|
343
343
|
let castValue = '';
|
|
344
|
-
if (parseInt(statement.value)) {
|
|
344
|
+
if (!isNaN(statement.value) && parseInt(statement.value)) {
|
|
345
345
|
castValue = '::int';
|
|
346
|
-
} else if (parseFloat(statement.value)) {
|
|
346
|
+
} else if (!isNaN(statement.value) && parseFloat(statement.value)) {
|
|
347
347
|
castValue = '::float';
|
|
348
348
|
} else {
|
|
349
349
|
castValue = " #>> '{}'";
|
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
* @param { import("knex").Knex } knex
|
|
3
3
|
* @returns { Promise<void> }
|
|
4
4
|
*/
|
|
5
|
-
exports.seed = function(knex) {
|
|
5
|
+
exports.seed = async function(knex) {
|
|
6
6
|
// Deletes ALL existing entries
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
{id: 3, colName: 'rowValue3'}
|
|
14
|
-
]);
|
|
15
|
-
});
|
|
7
|
+
await knex('table_name').del()
|
|
8
|
+
await knex('table_name').insert([
|
|
9
|
+
{id: 1, colName: 'rowValue1'},
|
|
10
|
+
{id: 2, colName: 'rowValue2'},
|
|
11
|
+
{id: 3, colName: 'rowValue3'}
|
|
12
|
+
]);
|
|
16
13
|
};
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -2210,7 +2210,7 @@ export declare namespace Knex {
|
|
|
2210
2210
|
notNullable(): ColumnBuilder;
|
|
2211
2211
|
nullable(): ColumnBuilder;
|
|
2212
2212
|
comment(value: string): ColumnBuilder;
|
|
2213
|
-
alter(options
|
|
2213
|
+
alter(options?: Readonly<{alterNullable?: boolean, alterType?: boolean}>): ColumnBuilder;
|
|
2214
2214
|
queryContext(context: any): ColumnBuilder;
|
|
2215
2215
|
after(columnName: string): ColumnBuilder;
|
|
2216
2216
|
first(): ColumnBuilder;
|
|
@@ -2662,7 +2662,7 @@ export declare namespace Knex {
|
|
|
2662
2662
|
interface MigrationSource<TMigrationSpec> {
|
|
2663
2663
|
getMigrations(loadExtensions: readonly string[]): Promise<TMigrationSpec[]>;
|
|
2664
2664
|
getMigrationName(migration: TMigrationSpec): string;
|
|
2665
|
-
getMigration(migration: TMigrationSpec): Migration
|
|
2665
|
+
getMigration(migration: TMigrationSpec): Promise<Migration>;
|
|
2666
2666
|
}
|
|
2667
2667
|
|
|
2668
2668
|
interface MigratorConfig {
|