knex 0.95.13 → 1.0.1
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 +74 -3
- package/README.md +1 -1
- package/UPGRADING.md +7 -0
- package/lib/client.js +14 -1
- package/lib/constants.js +2 -0
- package/lib/dialects/better-sqlite3/index.js +72 -0
- package/lib/dialects/cockroachdb/crdb-querycompiler.js +87 -33
- package/lib/dialects/cockroachdb/crdb-tablecompiler.js +19 -0
- package/lib/dialects/cockroachdb/index.js +13 -0
- package/lib/dialects/mssql/index.js +0 -11
- package/lib/dialects/mssql/query/mssql-querycompiler.js +122 -64
- package/lib/dialects/mssql/schema/mssql-columncompiler.js +41 -6
- package/lib/dialects/mssql/schema/mssql-tablecompiler.js +24 -9
- package/lib/dialects/mssql/schema/mssql-viewcompiler.js +15 -1
- package/lib/dialects/mysql/index.js +3 -7
- package/lib/dialects/mysql/query/mysql-querycompiler.js +91 -5
- package/lib/dialects/mysql/schema/mysql-columncompiler.js +32 -5
- package/lib/dialects/mysql/schema/mysql-tablecompiler.js +28 -4
- package/lib/dialects/mysql2/index.js +7 -4
- package/lib/dialects/oracle/query/oracle-querycompiler.js +7 -6
- package/lib/dialects/oracle/schema/internal/trigger.js +1 -1
- package/lib/dialects/oracle/schema/oracle-columncompiler.js +10 -4
- package/lib/dialects/oracle/schema/oracle-tablecompiler.js +17 -6
- package/lib/dialects/oracledb/index.js +0 -4
- package/lib/dialects/oracledb/query/oracledb-querycompiler.js +104 -0
- package/lib/dialects/oracledb/schema/oracledb-columncompiler.js +23 -0
- package/lib/dialects/postgres/index.js +21 -6
- package/lib/dialects/postgres/query/pg-querybuilder.js +8 -0
- package/lib/dialects/postgres/query/pg-querycompiler.js +166 -5
- package/lib/dialects/postgres/schema/pg-columncompiler.js +24 -4
- package/lib/dialects/postgres/schema/pg-tablecompiler.js +55 -47
- package/lib/dialects/redshift/index.js +12 -0
- package/lib/dialects/redshift/query/redshift-querycompiler.js +62 -26
- package/lib/dialects/redshift/schema/redshift-columncompiler.js +2 -1
- package/lib/dialects/redshift/schema/redshift-tablecompiler.js +4 -1
- package/lib/dialects/sqlite3/index.js +18 -4
- package/lib/dialects/sqlite3/query/sqlite-querycompiler.js +85 -18
- package/lib/dialects/sqlite3/schema/ddl.js +274 -282
- package/lib/dialects/sqlite3/schema/internal/sqlite-ddl-operations.js +18 -8
- package/lib/dialects/sqlite3/schema/sqlite-columncompiler.js +20 -0
- package/lib/dialects/sqlite3/schema/sqlite-compiler.js +16 -12
- package/lib/dialects/sqlite3/schema/sqlite-tablecompiler.js +15 -5
- package/lib/dialects/sqlite3/schema/sqlite-viewcompiler.js +31 -2
- package/lib/execution/runner.js +37 -2
- package/lib/knex-builder/FunctionHelper.js +21 -0
- package/lib/migrations/common/MigrationsLoader.js +36 -0
- package/lib/migrations/migrate/MigrationGenerator.js +1 -1
- package/lib/migrations/migrate/Migrator.js +20 -23
- package/lib/migrations/migrate/migration-list-resolver.js +2 -5
- package/lib/migrations/migrate/{configuration-merger.js → migrator-configuration-merger.js} +2 -4
- package/lib/migrations/migrate/sources/fs-migrations.js +4 -29
- package/lib/migrations/migrate/stub/js.stub +8 -1
- package/lib/migrations/migrate/stub/knexfile-js.stub +3 -0
- package/lib/migrations/migrate/stub/knexfile-ts.stub +5 -2
- package/lib/migrations/migrate/table-creator.js +6 -5
- package/lib/migrations/seed/Seeder.js +25 -92
- package/lib/migrations/seed/seeder-configuration-merger.js +60 -0
- package/lib/migrations/seed/sources/fs-seeds.js +65 -0
- package/lib/migrations/seed/stub/js.stub +4 -1
- package/lib/migrations/util/import-file.js +0 -1
- package/lib/query/joinclause.js +24 -5
- package/lib/query/method-constants.js +37 -0
- package/lib/query/querybuilder.js +230 -5
- package/lib/query/querycompiler.js +269 -84
- package/lib/schema/columnbuilder.js +8 -0
- package/lib/schema/columncompiler.js +132 -5
- package/lib/schema/compiler.js +1 -0
- package/lib/schema/tablebuilder.js +41 -8
- package/lib/schema/tablecompiler.js +57 -0
- package/lib/schema/viewcompiler.js +13 -10
- package/package.json +35 -22
- package/scripts/docker-compose.yml +7 -7
- package/scripts/oracledb-install-driver-libs.sh +82 -0
- package/scripts/runkit-example.js +1 -1
- package/scripts/stress-test/docker-compose.yml +3 -3
- package/scripts/stress-test/knex-stress-test.js +1 -1
- package/scripts/stress-test/reconnect-test-mysql-based-drivers.js +1 -1
- package/types/index.d.ts +124 -20
|
@@ -44,12 +44,16 @@ class TableCompiler_PG extends TableCompiler {
|
|
|
44
44
|
const createStatement = ifNot
|
|
45
45
|
? 'create table if not exists '
|
|
46
46
|
: 'create table ';
|
|
47
|
-
const columnsSql = ' (' + columns.sql.join(', ') + ')';
|
|
47
|
+
const columnsSql = ' (' + columns.sql.join(', ') + this._addChecks() + ')';
|
|
48
48
|
let sql =
|
|
49
49
|
createStatement +
|
|
50
50
|
this.tableName() +
|
|
51
51
|
(like && this.tableNameLike()
|
|
52
|
-
? ' (like ' +
|
|
52
|
+
? ' (like ' +
|
|
53
|
+
this.tableNameLike() +
|
|
54
|
+
' including all' +
|
|
55
|
+
(columns.sql.length ? ', ' + columns.sql.join(', ') : '') +
|
|
56
|
+
')'
|
|
53
57
|
: columnsSql);
|
|
54
58
|
if (this.single.inherits)
|
|
55
59
|
sql += ` inherits (${this.formatter.wrap(this.single.inherits)})`;
|
|
@@ -65,51 +69,7 @@ class TableCompiler_PG extends TableCompiler {
|
|
|
65
69
|
if (prefix === this.alterColumnsPrefix) {
|
|
66
70
|
// alter columns
|
|
67
71
|
for (const col of colCompilers) {
|
|
68
|
-
|
|
69
|
-
const type = col.getColumnType();
|
|
70
|
-
// We'd prefer to call this.formatter.wrapAsIdentifier here instead, however the context passed to
|
|
71
|
-
// `this` instance is not that of the column, but of the table. Thus, we unfortunately have to call
|
|
72
|
-
// `wrapIdentifier` here as well (it is already called once on the initial column operation) to give
|
|
73
|
-
// our `alter` operation the correct `queryContext`. Refer to issue #2606 and PR #2612.
|
|
74
|
-
const colName = this.client.wrapIdentifier(
|
|
75
|
-
col.getColumnName(),
|
|
76
|
-
col.columnBuilder.queryContext()
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
// To alter enum columns they must be cast to text first
|
|
80
|
-
const isEnum = col.type === 'enu';
|
|
81
|
-
|
|
82
|
-
this.pushQuery({
|
|
83
|
-
sql: `alter table ${quotedTableName} alter column ${colName} drop default`,
|
|
84
|
-
bindings: [],
|
|
85
|
-
});
|
|
86
|
-
this.pushQuery({
|
|
87
|
-
sql: `alter table ${quotedTableName} alter column ${colName} drop not null`,
|
|
88
|
-
bindings: [],
|
|
89
|
-
});
|
|
90
|
-
this.pushQuery({
|
|
91
|
-
sql: `alter table ${quotedTableName} alter column ${colName} type ${type} using (${colName}${
|
|
92
|
-
isEnum ? '::text::' : '::'
|
|
93
|
-
}${type})`,
|
|
94
|
-
bindings: [],
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
const defaultTo = col.modified['defaultTo'];
|
|
98
|
-
if (defaultTo) {
|
|
99
|
-
const modifier = col.defaultTo.apply(col, defaultTo);
|
|
100
|
-
this.pushQuery({
|
|
101
|
-
sql: `alter table ${quotedTableName} alter column ${colName} set ${modifier}`,
|
|
102
|
-
bindings: [],
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const nullable = col.modified['nullable'];
|
|
107
|
-
if (nullable && nullable[0] === false) {
|
|
108
|
-
this.pushQuery({
|
|
109
|
-
sql: `alter table ${quotedTableName} alter column ${colName} set not null`,
|
|
110
|
-
bindings: [],
|
|
111
|
-
});
|
|
112
|
-
}
|
|
72
|
+
this._addColumn(col);
|
|
113
73
|
}
|
|
114
74
|
} else {
|
|
115
75
|
// base class implementation for normal add
|
|
@@ -117,6 +77,54 @@ class TableCompiler_PG extends TableCompiler {
|
|
|
117
77
|
}
|
|
118
78
|
}
|
|
119
79
|
|
|
80
|
+
_addColumn(col) {
|
|
81
|
+
const quotedTableName = this.tableName();
|
|
82
|
+
const type = col.getColumnType();
|
|
83
|
+
// We'd prefer to call this.formatter.wrapAsIdentifier here instead, however the context passed to
|
|
84
|
+
// `this` instance is not that of the column, but of the table. Thus, we unfortunately have to call
|
|
85
|
+
// `wrapIdentifier` here as well (it is already called once on the initial column operation) to give
|
|
86
|
+
// our `alter` operation the correct `queryContext`. Refer to issue #2606 and PR #2612.
|
|
87
|
+
const colName = this.client.wrapIdentifier(
|
|
88
|
+
col.getColumnName(),
|
|
89
|
+
col.columnBuilder.queryContext()
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// To alter enum columns they must be cast to text first
|
|
93
|
+
const isEnum = col.type === 'enu';
|
|
94
|
+
|
|
95
|
+
this.pushQuery({
|
|
96
|
+
sql: `alter table ${quotedTableName} alter column ${colName} drop default`,
|
|
97
|
+
bindings: [],
|
|
98
|
+
});
|
|
99
|
+
this.pushQuery({
|
|
100
|
+
sql: `alter table ${quotedTableName} alter column ${colName} drop not null`,
|
|
101
|
+
bindings: [],
|
|
102
|
+
});
|
|
103
|
+
this.pushQuery({
|
|
104
|
+
sql: `alter table ${quotedTableName} alter column ${colName} type ${type} using (${colName}${
|
|
105
|
+
isEnum ? '::text::' : '::'
|
|
106
|
+
}${type})`,
|
|
107
|
+
bindings: [],
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const defaultTo = col.modified['defaultTo'];
|
|
111
|
+
if (defaultTo) {
|
|
112
|
+
const modifier = col.defaultTo.apply(col, defaultTo);
|
|
113
|
+
this.pushQuery({
|
|
114
|
+
sql: `alter table ${quotedTableName} alter column ${colName} set ${modifier}`,
|
|
115
|
+
bindings: [],
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const nullable = col.modified['nullable'];
|
|
120
|
+
if (nullable && nullable[0] === false) {
|
|
121
|
+
this.pushQuery({
|
|
122
|
+
sql: `alter table ${quotedTableName} alter column ${colName} set not null`,
|
|
123
|
+
bindings: [],
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
120
128
|
// Compiles the comment on the table.
|
|
121
129
|
comment(comment) {
|
|
122
130
|
this.pushQuery(
|
|
@@ -63,6 +63,18 @@ class Client_Redshift extends Client_PG {
|
|
|
63
63
|
}
|
|
64
64
|
return resp;
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
toPathForJson(jsonPath, builder, bindingsHolder) {
|
|
68
|
+
return jsonPath
|
|
69
|
+
.replace(/^(\$\.)/, '') // remove the first dollar
|
|
70
|
+
.split('.')
|
|
71
|
+
.map(
|
|
72
|
+
function (v) {
|
|
73
|
+
return this.parameter(v, builder, bindingsHolder);
|
|
74
|
+
}.bind(this)
|
|
75
|
+
)
|
|
76
|
+
.join(', ');
|
|
77
|
+
}
|
|
66
78
|
}
|
|
67
79
|
|
|
68
80
|
Object.assign(Client_Redshift.prototype, {
|
|
@@ -4,7 +4,9 @@ const QueryCompiler = require('../../../query/querycompiler');
|
|
|
4
4
|
const QueryCompiler_PG = require('../../postgres/query/pg-querycompiler');
|
|
5
5
|
|
|
6
6
|
const identity = require('lodash/identity');
|
|
7
|
-
const
|
|
7
|
+
const {
|
|
8
|
+
columnize: columnize_,
|
|
9
|
+
} = require('../../../formatter/wrappingFormatter');
|
|
8
10
|
|
|
9
11
|
class QueryCompiler_Redshift extends QueryCompiler_PG {
|
|
10
12
|
truncate() {
|
|
@@ -87,40 +89,74 @@ class QueryCompiler_Redshift extends QueryCompiler_PG {
|
|
|
87
89
|
schema = this.client.customWrapIdentifier(schema, identity);
|
|
88
90
|
}
|
|
89
91
|
|
|
90
|
-
|
|
92
|
+
const sql =
|
|
91
93
|
'select * from information_schema.columns where table_name = ? and table_catalog = ?';
|
|
92
94
|
const bindings = [
|
|
93
95
|
table.toLowerCase(),
|
|
94
96
|
this.client.database().toLowerCase(),
|
|
95
97
|
];
|
|
96
98
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
return this._buildColumnInfoQuery(schema, sql, bindings, column);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
jsonExtract(params) {
|
|
103
|
+
let extractions;
|
|
104
|
+
if (Array.isArray(params.column)) {
|
|
105
|
+
extractions = params.column;
|
|
100
106
|
} else {
|
|
101
|
-
|
|
107
|
+
extractions = [params];
|
|
102
108
|
}
|
|
109
|
+
return extractions
|
|
110
|
+
.map((extraction) => {
|
|
111
|
+
const jsonCol = `json_extract_path_text(${columnize_(
|
|
112
|
+
extraction.column || extraction[0],
|
|
113
|
+
this.builder,
|
|
114
|
+
this.client,
|
|
115
|
+
this.bindingsHolder
|
|
116
|
+
)}, ${this.client.toPathForJson(
|
|
117
|
+
params.path || extraction[1],
|
|
118
|
+
this.builder,
|
|
119
|
+
this.bindingsHolder
|
|
120
|
+
)})`;
|
|
121
|
+
const alias = extraction.alias || extraction[2];
|
|
122
|
+
return alias
|
|
123
|
+
? this.client.alias(jsonCol, this.formatter.wrap(alias))
|
|
124
|
+
: jsonCol;
|
|
125
|
+
})
|
|
126
|
+
.join(', ');
|
|
127
|
+
}
|
|
103
128
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
129
|
+
jsonSet(params) {
|
|
130
|
+
throw new Error('Json set is not supported by Redshift');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
jsonInsert(params) {
|
|
134
|
+
throw new Error('Json insert is not supported by Redshift');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
jsonRemove(params) {
|
|
138
|
+
throw new Error('Json remove is not supported by Redshift');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
whereJsonPath(statement) {
|
|
142
|
+
return this._whereJsonPath(
|
|
143
|
+
'json_extract_path_text',
|
|
144
|
+
Object.assign({}, statement, {
|
|
145
|
+
path: this.client.toPathForJson(statement.path),
|
|
146
|
+
})
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
whereJsonSupersetOf(statement) {
|
|
151
|
+
throw new Error('Json superset is not supported by Redshift');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
whereJsonSubsetOf(statement) {
|
|
155
|
+
throw new Error('Json subset is not supported by Redshift');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
onJsonPathEquals(clause) {
|
|
159
|
+
return this._onJsonPathEquals('json_extract_path_text', clause);
|
|
124
160
|
}
|
|
125
161
|
}
|
|
126
162
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// -------
|
|
3
3
|
|
|
4
4
|
const ColumnCompiler_PG = require('../../postgres/schema/pg-columncompiler');
|
|
5
|
+
const ColumnCompiler = require('../../../schema/columncompiler');
|
|
5
6
|
|
|
6
7
|
class ColumnCompiler_Redshift extends ColumnCompiler_PG {
|
|
7
8
|
constructor() {
|
|
@@ -54,7 +55,7 @@ ColumnCompiler_Redshift.prototype.mediumblob = 'varchar(16777218)';
|
|
|
54
55
|
ColumnCompiler_Redshift.prototype.set = 'text';
|
|
55
56
|
ColumnCompiler_Redshift.prototype.text = 'varchar(max)';
|
|
56
57
|
ColumnCompiler_Redshift.prototype.tinyblob = 'varchar(256)';
|
|
57
|
-
ColumnCompiler_Redshift.prototype.uuid =
|
|
58
|
+
ColumnCompiler_Redshift.prototype.uuid = ColumnCompiler.prototype.uuid;
|
|
58
59
|
ColumnCompiler_Redshift.prototype.varbinary = 'varchar(max)';
|
|
59
60
|
ColumnCompiler_Redshift.prototype.bigint = 'bigint';
|
|
60
61
|
ColumnCompiler_Redshift.prototype.bool = 'boolean';
|
|
@@ -30,7 +30,7 @@ class TableCompiler_Redshift extends TableCompiler_PG {
|
|
|
30
30
|
const createStatement = ifNot
|
|
31
31
|
? 'create table if not exists '
|
|
32
32
|
: 'create table ';
|
|
33
|
-
const columnsSql = ' (' + columns.sql.join(', ') + ')';
|
|
33
|
+
const columnsSql = ' (' + columns.sql.join(', ') + this._addChecks() + ')';
|
|
34
34
|
let sql =
|
|
35
35
|
createStatement +
|
|
36
36
|
this.tableName() +
|
|
@@ -45,6 +45,9 @@ class TableCompiler_Redshift extends TableCompiler_PG {
|
|
|
45
45
|
});
|
|
46
46
|
const hasComment = has(this.single, 'comment');
|
|
47
47
|
if (hasComment) this.comment(this.single.comment);
|
|
48
|
+
if (like) {
|
|
49
|
+
this.addColumns(columns, this.addColumnsPrefix);
|
|
50
|
+
}
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
primary(columns, constraintName) {
|
|
@@ -29,7 +29,7 @@ class Client_SQLite3 extends Client {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
_driver() {
|
|
32
|
-
return require('sqlite3');
|
|
32
|
+
return require('@vscode/sqlite3');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
schemaCompiler() {
|
|
@@ -132,6 +132,7 @@ class Client_SQLite3 extends Client {
|
|
|
132
132
|
// We need the context here, as it contains
|
|
133
133
|
// the "this.lastID" or "this.changes"
|
|
134
134
|
obj.context = this;
|
|
135
|
+
|
|
135
136
|
return resolver(obj);
|
|
136
137
|
});
|
|
137
138
|
});
|
|
@@ -144,6 +145,7 @@ class Client_SQLite3 extends Client {
|
|
|
144
145
|
return new Promise(function (resolver, rejecter) {
|
|
145
146
|
stream.on('error', rejecter);
|
|
146
147
|
stream.on('end', resolver);
|
|
148
|
+
|
|
147
149
|
return client
|
|
148
150
|
._query(connection, obj)
|
|
149
151
|
.then((obj) => obj.response)
|
|
@@ -160,7 +162,7 @@ class Client_SQLite3 extends Client {
|
|
|
160
162
|
// Ensures the response is returned in the same format as other clients.
|
|
161
163
|
processResponse(obj, runner) {
|
|
162
164
|
const ctx = obj.context;
|
|
163
|
-
const { response } = obj;
|
|
165
|
+
const { response, returning } = obj;
|
|
164
166
|
if (obj.output) return obj.output.call(runner, response);
|
|
165
167
|
switch (obj.method) {
|
|
166
168
|
case 'select':
|
|
@@ -169,14 +171,26 @@ class Client_SQLite3 extends Client {
|
|
|
169
171
|
return response[0];
|
|
170
172
|
case 'pluck':
|
|
171
173
|
return map(response, obj.pluck);
|
|
172
|
-
case 'insert':
|
|
174
|
+
case 'insert': {
|
|
175
|
+
if (returning) {
|
|
176
|
+
if (response) {
|
|
177
|
+
return response;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ToDo Implement after https://github.com/microsoft/vscode-node-sqlite3/issues/15 is resolved
|
|
181
|
+
this.logger.warn(
|
|
182
|
+
'node-sqlite3 does not currently support RETURNING clause'
|
|
183
|
+
);
|
|
184
|
+
}
|
|
173
185
|
return [ctx.lastID];
|
|
186
|
+
}
|
|
174
187
|
case 'del':
|
|
175
188
|
case 'update':
|
|
176
189
|
case 'counter':
|
|
177
190
|
return ctx.changes;
|
|
178
|
-
default:
|
|
191
|
+
default: {
|
|
179
192
|
return response;
|
|
193
|
+
}
|
|
180
194
|
}
|
|
181
195
|
}
|
|
182
196
|
|
|
@@ -9,7 +9,10 @@ const reduce = require('lodash/reduce');
|
|
|
9
9
|
const QueryCompiler = require('../../../query/querycompiler');
|
|
10
10
|
const noop = require('../../../util/noop');
|
|
11
11
|
const { isString } = require('../../../util/is');
|
|
12
|
-
const {
|
|
12
|
+
const {
|
|
13
|
+
wrapString,
|
|
14
|
+
columnize: columnize_,
|
|
15
|
+
} = require('../../../formatter/wrappingFormatter');
|
|
13
16
|
|
|
14
17
|
const emptyStr = constant('');
|
|
15
18
|
|
|
@@ -17,14 +20,6 @@ class QueryCompiler_SQLite3 extends QueryCompiler {
|
|
|
17
20
|
constructor(client, builder, formatter) {
|
|
18
21
|
super(client, builder, formatter);
|
|
19
22
|
|
|
20
|
-
const { returning } = this.single;
|
|
21
|
-
|
|
22
|
-
if (returning) {
|
|
23
|
-
this.client.logger.warn(
|
|
24
|
-
'.returning() is not supported by sqlite3 and will not have any effect.'
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
23
|
// The locks are not applicable in SQLite3
|
|
29
24
|
this.forShare = emptyStr;
|
|
30
25
|
this.forKeyShare = emptyStr;
|
|
@@ -47,20 +42,28 @@ class QueryCompiler_SQLite3 extends QueryCompiler {
|
|
|
47
42
|
insertValues[0] &&
|
|
48
43
|
isEmpty(insertValues[0])
|
|
49
44
|
) {
|
|
50
|
-
return
|
|
45
|
+
return {
|
|
46
|
+
sql: sql + this._emptyInsertValue,
|
|
47
|
+
};
|
|
51
48
|
}
|
|
52
49
|
} else if (typeof insertValues === 'object' && isEmpty(insertValues)) {
|
|
53
|
-
return
|
|
50
|
+
return {
|
|
51
|
+
sql: sql + this._emptyInsertValue,
|
|
52
|
+
};
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
const insertData = this._prepInsert(insertValues);
|
|
57
56
|
|
|
58
57
|
if (isString(insertData)) {
|
|
59
|
-
return
|
|
58
|
+
return {
|
|
59
|
+
sql: sql + insertData,
|
|
60
|
+
};
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
if (insertData.columns.length === 0) {
|
|
63
|
-
return
|
|
64
|
+
return {
|
|
65
|
+
sql: '',
|
|
66
|
+
};
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
sql += `(${this.formatter.columnize(insertData.columns)})`;
|
|
@@ -96,7 +99,15 @@ class QueryCompiler_SQLite3 extends QueryCompiler {
|
|
|
96
99
|
if (wheres) sql += ` ${wheres}`;
|
|
97
100
|
}
|
|
98
101
|
|
|
99
|
-
|
|
102
|
+
const { returning } = this.single;
|
|
103
|
+
if (returning) {
|
|
104
|
+
sql += this._returning(returning);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
sql,
|
|
109
|
+
returning,
|
|
110
|
+
};
|
|
100
111
|
}
|
|
101
112
|
|
|
102
113
|
const blocks = [];
|
|
@@ -129,7 +140,13 @@ class QueryCompiler_SQLite3 extends QueryCompiler {
|
|
|
129
140
|
' where true' + this._merge(merge.updates, onConflict, insertValues);
|
|
130
141
|
}
|
|
131
142
|
|
|
132
|
-
|
|
143
|
+
const { returning } = this.single;
|
|
144
|
+
if (returning) sql += this._returning(returning);
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
sql,
|
|
148
|
+
returning,
|
|
149
|
+
};
|
|
133
150
|
}
|
|
134
151
|
|
|
135
152
|
_ignore(columns) {
|
|
@@ -185,6 +202,10 @@ class QueryCompiler_SQLite3 extends QueryCompiler {
|
|
|
185
202
|
}
|
|
186
203
|
}
|
|
187
204
|
|
|
205
|
+
_returning(value) {
|
|
206
|
+
return value ? ` returning ${this.formatter.columnize(value)}` : '';
|
|
207
|
+
}
|
|
208
|
+
|
|
188
209
|
// Compile a truncate table statement into SQL.
|
|
189
210
|
truncate() {
|
|
190
211
|
const { table } = this.single;
|
|
@@ -241,11 +262,57 @@ class QueryCompiler_SQLite3 extends QueryCompiler {
|
|
|
241
262
|
|
|
242
263
|
// Workaround for offset only,
|
|
243
264
|
// see http://stackoverflow.com/questions/10491492/sqllite-with-skip-offset-only-not-limit
|
|
244
|
-
|
|
245
|
-
|
|
265
|
+
this.single.limit = noLimit ? -1 : this.single.limit;
|
|
266
|
+
return `limit ${this._getValueOrParameterFromAttribute('limit')}`;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Json functions
|
|
270
|
+
jsonExtract(params) {
|
|
271
|
+
return this._jsonExtract('json_extract', params);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
jsonSet(params) {
|
|
275
|
+
return this._jsonSet('json_set', params);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
jsonInsert(params) {
|
|
279
|
+
return this._jsonSet('json_insert', params);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
jsonRemove(params) {
|
|
283
|
+
const jsonCol = `json_remove(${columnize_(
|
|
284
|
+
params.column,
|
|
285
|
+
this.builder,
|
|
286
|
+
this.client,
|
|
287
|
+
this.bindingsHolder
|
|
288
|
+
)},${this.client.parameter(
|
|
289
|
+
params.path,
|
|
246
290
|
this.builder,
|
|
247
291
|
this.bindingsHolder
|
|
248
|
-
)}`;
|
|
292
|
+
)})`;
|
|
293
|
+
return params.alias
|
|
294
|
+
? this.client.alias(jsonCol, this.formatter.wrap(params.alias))
|
|
295
|
+
: jsonCol;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
whereJsonPath(statement) {
|
|
299
|
+
return this._whereJsonPath('json_extract', statement);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
whereJsonSupersetOf(statement) {
|
|
303
|
+
throw new Error(
|
|
304
|
+
'Json superset where clause not actually supported by SQLite'
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
whereJsonSubsetOf(statement) {
|
|
309
|
+
throw new Error(
|
|
310
|
+
'Json subset where clause not actually supported by SQLite'
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
onJsonPathEquals(clause) {
|
|
315
|
+
return this._onJsonPathEquals('json_extract', clause);
|
|
249
316
|
}
|
|
250
317
|
}
|
|
251
318
|
|