Skip to content

Commit be3acbe

Browse files
committed
fix: fixed buildQuery
1 parent 118b122 commit be3acbe

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/dialects/base/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ function Dialect(builder) {
3434
}
3535

3636
Dialect.prototype.buildQuery = function (query) {
37+
// Backwards compatibility: infer query type if not specified
38+
if (!query.type) {
39+
// Infer type based on properties
40+
if (query.values && !query.condition) {
41+
query = { ...query, type: 'insert' };
42+
} else if (query.values && query.condition) {
43+
query = { ...query, type: 'update' };
44+
} else if (query.condition && !query.fields && !query.table) {
45+
query = { ...query, type: 'remove' };
46+
} else {
47+
query = { ...query, type: 'select' };
48+
}
49+
}
50+
3751
const template = this.templates.get(query.type);
3852

3953
if (!template) {

lib/dialects/postgresql/blocks.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,10 @@ module.exports = function (dialect) {
575575
return field;
576576
}
577577

578+
if (has(term, 'expression')) {
579+
return dialect.buildExpression(term.expression);
580+
}
581+
578582
if (objectUtils.hasSome(term, termKeys)) {
579583
const termKey = keys(term)[0];
580584
const termValue = term[termKey];
@@ -598,6 +602,10 @@ module.exports = function (dialect) {
598602
}
599603

600604
if (isObject(term)) {
605+
if (has(term, 'expression')) {
606+
return dialect.buildExpression(term.expression);
607+
}
608+
601609
if (objectUtils.hasSome(term, termKeys)) {
602610
const termKey = keys(term)[0];
603611
const termValue = term[termKey];
@@ -621,6 +629,10 @@ module.exports = function (dialect) {
621629
}
622630

623631
if (isObject(term)) {
632+
if (has(term, 'expression')) {
633+
return dialect.buildExpression(term.expression);
634+
}
635+
624636
if (objectUtils.hasSome(term, termKeys)) {
625637
const termKey = keys(term)[0];
626638
const termValue = term[termKey];

0 commit comments

Comments
 (0)