Skip to content

Commit 0d14d9d

Browse files
committed
fix: fixed returning clause, update query, empty condition, and modifier block
1 parent ada3db8 commit 0d14d9d

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

lib/dialects/base/blocks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ module.exports = function (dialect) {
165165
dialect.blocks.add('modifier', (parameters) => {
166166
const { modifier } = parameters;
167167

168+
if (isUndefined(modifier) || modifier === null) {
169+
return '';
170+
}
171+
168172
if (!isObject(modifier)) {
169173
throw new TypeError(
170174
'Invalid `modifier` property type "' + typeof modifier + '"'

lib/dialects/base/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ Dialect.prototype.buildQuery = function (query) {
4040
throw new Error('Unknown query type "' + query.type + '"');
4141
}
4242

43+
// Backwards compatibility: map 'values' to 'modifier' for update queries
44+
if (query.type === 'update' && query.values && !query.modifier) {
45+
query = { ...query, modifier: query.values };
46+
}
47+
4348
return this.buildTemplate(template.pattern, query);
4449
};
4550

@@ -201,6 +206,30 @@ Dialect.prototype.wrapIdentifier = function (name) {
201206
return name;
202207
}
203208

209+
// Don't wrap special SQL keywords and wildcards
210+
if (name === '*') {
211+
return name;
212+
}
213+
214+
// Don't wrap SQL functions (anything with parentheses)
215+
if (name.includes('(') && name.includes(')')) {
216+
return name;
217+
}
218+
219+
// Don't wrap SQL expressions (CASE, SELECT, etc.)
220+
const upperName = name.toUpperCase().trim();
221+
if (
222+
upperName.startsWith('CASE ') ||
223+
upperName.startsWith('SELECT ') ||
224+
upperName.startsWith('(SELECT ') ||
225+
upperName.includes(' WHEN ') ||
226+
upperName.includes(' THEN ') ||
227+
upperName.includes(' ELSE ') ||
228+
upperName.includes(' END')
229+
) {
230+
return name;
231+
}
232+
204233
return '"' + name + '"';
205234
};
206235

lib/dialects/postgresql/blocks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ module.exports = function (dialect) {
164164
dialect.blocks.add('modifier', (parameters) => {
165165
const { modifier } = parameters;
166166

167+
if (isUndefined(modifier) || modifier === null) {
168+
return '';
169+
}
170+
167171
if (!isObject(modifier)) {
168172
throw new TypeError(
169173
'Invalid `modifier` property type "' + typeof modifier + '"'

0 commit comments

Comments
 (0)