knex 3.2.8 → 3.2.9
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 +11 -0
- package/lib/dialects/mysql/query/mysql-querycompiler.js +11 -2
- package/lib/dialects/postgres/index.js +3 -1
- package/lib/dialects/sqlite3/query/sqlite-querycompiler.js +8 -6
- package/lib/query/querycompiler.js +10 -4
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Master (Unreleased)
|
|
2
2
|
|
|
3
|
+
# 3.2.9 - 3 April, 2026
|
|
4
|
+
|
|
5
|
+
### Bug fixes
|
|
6
|
+
|
|
7
|
+
- fix: support DELETE... LIMIT in dialects that support it (mysql), but continue to disallow ones that don't [#6429](https://github.com/knex/knex/issues/6429)
|
|
8
|
+
- fix(postgres): escape double quotes in searchPath to prevent SQL injection [#6411](https://github.com/knex/knex/issues/6411)
|
|
9
|
+
- fix(sqlite): append RETURNING statement when insert empty row [#5471](https://github.com/knex/knex/issues/5471)
|
|
10
|
+
- fix: add type support for Array<Buffer> [#6428](https://github.com/knex/knex/issues/6428)
|
|
11
|
+
|
|
12
|
+
# 3.2.8 - 30 March, 2026
|
|
13
|
+
|
|
3
14
|
### Bug fixes
|
|
4
15
|
|
|
5
16
|
- Reverts the breaking changes added in [#6227](https://github.com/knex/knex/issues/6227). This means that the ESM import of Knex is reverted to `import { knex } from 'knex/knex.mjs` [#6422](https://github.com/knex/knex/issues/6422)
|
|
@@ -27,12 +27,15 @@ class QueryCompiler_MySQL extends QueryCompiler {
|
|
|
27
27
|
|
|
28
28
|
this._emptyInsertValue = '() values ()';
|
|
29
29
|
}
|
|
30
|
-
// Compiles
|
|
30
|
+
// Compiles a `delete` query, allowing comments and LIMIT.
|
|
31
31
|
del() {
|
|
32
32
|
const sql = super.del();
|
|
33
33
|
if (sql === '') return sql;
|
|
34
34
|
const comments = this.comments();
|
|
35
|
-
|
|
35
|
+
const limit = this.limit();
|
|
36
|
+
return (
|
|
37
|
+
(comments === '' ? '' : comments + ' ') + sql + (limit ? ` ${limit}` : '')
|
|
38
|
+
);
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
// Compiles an `insert` query, allowing for multiple
|
|
@@ -287,6 +290,12 @@ class QueryCompiler_MySQL extends QueryCompiler {
|
|
|
287
290
|
}
|
|
288
291
|
}
|
|
289
292
|
|
|
293
|
+
// MySQL supports LIMIT on single-table DELETE statements.
|
|
294
|
+
QueryCompiler_MySQL.prototype.invalidClauses = {
|
|
295
|
+
delete: ['having'],
|
|
296
|
+
truncate: ['where', 'having', 'limit'],
|
|
297
|
+
};
|
|
298
|
+
|
|
290
299
|
// Set the QueryBuilder & QueryCompiler on the client object,
|
|
291
300
|
// in case anyone wants to modify things to suit their own purposes.
|
|
292
301
|
module.exports = QueryCompiler_MySQL;
|
|
@@ -174,7 +174,9 @@ class Client_PG extends Client {
|
|
|
174
174
|
path = [path];
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
path = path
|
|
177
|
+
path = path
|
|
178
|
+
.map((schemaName) => `"${schemaName.replace(/"/g, '""')}"`)
|
|
179
|
+
.join(',');
|
|
178
180
|
|
|
179
181
|
return new Promise(function (resolver, rejecter) {
|
|
180
182
|
connection.query(`set search_path to ${path}`, function (err) {
|
|
@@ -42,14 +42,16 @@ class QueryCompiler_SQLite3 extends QueryCompiler {
|
|
|
42
42
|
insertValues[0] &&
|
|
43
43
|
isEmpty(insertValues[0])
|
|
44
44
|
) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
sql += this._emptyInsertValue;
|
|
46
|
+
const { returning } = this.single;
|
|
47
|
+
if (returning) sql += this._returning(returning);
|
|
48
|
+
return { sql, returning };
|
|
48
49
|
}
|
|
49
50
|
} else if (typeof insertValues === 'object' && isEmpty(insertValues)) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
sql += this._emptyInsertValue;
|
|
52
|
+
const { returning } = this.single;
|
|
53
|
+
if (returning) sql += this._returning(returning);
|
|
54
|
+
return { sql, returning };
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
const insertData = this._prepInsert(insertValues);
|
|
@@ -48,7 +48,7 @@ const methodAliases = {
|
|
|
48
48
|
first: 'select',
|
|
49
49
|
pluck: 'select',
|
|
50
50
|
};
|
|
51
|
-
const
|
|
51
|
+
const defaultInvalidClauses = {
|
|
52
52
|
delete: ['having', 'limit'],
|
|
53
53
|
truncate: ['where', 'having', 'limit'],
|
|
54
54
|
};
|
|
@@ -77,9 +77,12 @@ class QueryCompiler {
|
|
|
77
77
|
this.builder = this.formatter.builder;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
// Categorically refuse to execute certain queries that have defined certain clause groups
|
|
80
|
+
// Categorically refuse to execute certain queries that have defined certain clause groups.
|
|
81
81
|
// For example, if a "having" clause is defined but we're executing a "delete" query, that
|
|
82
82
|
// is never valid in any of the supported dialects.
|
|
83
|
+
//
|
|
84
|
+
// Dialects override `invalidClauses` on the prototype to adjust which clauses are
|
|
85
|
+
// disallowed for each verb (e.g. MySQL allows `limit` on `delete`).
|
|
83
86
|
_preValidate() {
|
|
84
87
|
// Query builders don't really store the SQL verb they expect to generate; this would
|
|
85
88
|
// be nicer if we could avoid the fanout of "call an arbitrary method on one of a dozen
|
|
@@ -87,12 +90,13 @@ class QueryCompiler {
|
|
|
87
90
|
// methods used by the codebase for now.
|
|
88
91
|
const method = this.method;
|
|
89
92
|
const verb = hasOwn(methodAliases, method) ? methodAliases[method] : method;
|
|
90
|
-
|
|
93
|
+
|
|
94
|
+
const invalid = this.invalidClauses[verb];
|
|
95
|
+
if (!invalid) return;
|
|
91
96
|
|
|
92
97
|
// For certain verbs, certain clauses just don't exist / aren't supported. The list
|
|
93
98
|
// here is intentionally not complete; it's just checking the things that allow users
|
|
94
99
|
// to make dangerous errors.
|
|
95
|
-
const invalid = invalidClauses[verb];
|
|
96
100
|
for (let i = 0; i < invalid.length; i++) {
|
|
97
101
|
const clause = invalid[i];
|
|
98
102
|
|
|
@@ -1631,4 +1635,6 @@ class QueryCompiler {
|
|
|
1631
1635
|
}
|
|
1632
1636
|
}
|
|
1633
1637
|
|
|
1638
|
+
QueryCompiler.prototype.invalidClauses = defaultInvalidClauses;
|
|
1639
|
+
|
|
1634
1640
|
module.exports = QueryCompiler;
|
package/package.json
CHANGED