Add more features to the query generator

This commit is contained in:
2026-04-18 14:59:23 +01:00
parent f3f1c42699
commit 9c5d39edfb
19 changed files with 375 additions and 83 deletions
+55 -10
View File
@@ -1,6 +1,7 @@
import type {
ServerQueryParamsJoin,
ServerQueryParamsJoinMatchObject,
SQLInsertGenValueType,
} from "../types";
type Param = {
@@ -10,6 +11,8 @@ type Param = {
};
export default function sqlGenGenJoinStr({ join, mtch, table_name }: Param) {
let values: SQLInsertGenValueType[] = [];
if (mtch.__batch) {
let btch_mtch = ``;
btch_mtch += `(`;
@@ -18,7 +21,17 @@ export default function sqlGenGenJoinStr({ join, mtch, table_name }: Param) {
const __mtch = mtch.__batch.matches[
i
] as ServerQueryParamsJoinMatchObject;
btch_mtch += `${sqlGenGenJoinStr({ join, mtch: __mtch, table_name })}`;
const { str, values: batch_values } = sqlGenGenJoinStr({
join,
mtch: __mtch,
table_name,
});
btch_mtch += str;
values.push(...batch_values);
if (i < mtch.__batch.matches.length - 1) {
btch_mtch += ` ${mtch.__batch.operator || "OR"} `;
}
@@ -26,19 +39,28 @@ export default function sqlGenGenJoinStr({ join, mtch, table_name }: Param) {
btch_mtch += `)`;
return btch_mtch;
return {
str: btch_mtch,
values,
};
}
return `${
const equality = mtch.raw_equality || "=";
const lhs = `${
typeof mtch.source == "object" ? mtch.source.tableName : table_name
}.${
typeof mtch.source == "object" ? mtch.source.fieldName : mtch.source
}=${(() => {
}.${typeof mtch.source == "object" ? mtch.source.fieldName : mtch.source}`;
const rhs = `${(() => {
if (mtch.targetLiteral) {
if (typeof mtch.targetLiteral == "number") {
return `${mtch.targetLiteral}`;
}
return `'${mtch.targetLiteral}'`;
values.push(mtch.targetLiteral);
// if (typeof mtch.targetLiteral == "number") {
// return `${mtch.targetLiteral}`;
// }
// return `'${mtch.targetLiteral}'`;
return `?`;
}
if (join.alias) {
@@ -61,4 +83,27 @@ export default function sqlGenGenJoinStr({ join, mtch, table_name }: Param) {
typeof mtch.target == "object" ? mtch.target.fieldName : mtch.target
}`;
})()}`;
if (mtch.between) {
values.push(mtch.between.min, mtch.between.max);
return {
str: `${lhs} BETWEEN ? AND ?`,
values,
};
}
if (mtch.not_between) {
values.push(mtch.not_between.min, mtch.not_between.max);
return {
str: `${lhs} NOT BETWEEN ? AND ?`,
values,
};
}
return {
str: `${lhs} ${equality} ${rhs}`,
values,
};
}