- Add bun test suite: SQL generator and value unit tests, plus MariaDB integration tests gated on BUN_MARIADB_TEST_DB - schema: add --dry-run and require confirmation (or --yes) before dropping tables/columns; block unapproved destructive statements - Always AND targetId with the query, regardless of searchOperator - Initialize lazily on first call; init throws instead of exiting - Generate IN (?, ?, ...) lists for IN / NOT IN - Share value binding between insert and update (booleans, embeddings, function values, "" -> NULL for non-text columns) - Keep Buffers and convert BigInt/Date without a JSON round-trip - DbSQL: report success for empty SELECT results - Run update() in a transaction with row locking - Key the client cache on the full connection config - Consolidate identifier quoting, drop dead code, merge column lookup - Read CLI version from package.json, pin @types/bun, chmod CLI on compile - Rebuild dist Co-Authored-By: Claude Opus 5.5 <[email protected]>
61 lines
2.0 KiB
JavaScript
61 lines
2.0 KiB
JavaScript
import { columnRef, sqlLogicalOperator, sqlRawComparison, } from "./sql-identifier";
|
|
export default function sqlGenGenJoinStr({ join, mtch, table_name }) {
|
|
let values = [];
|
|
if (mtch.__batch) {
|
|
let btch_mtch = ``;
|
|
btch_mtch += `(`;
|
|
for (let i = 0; i < mtch.__batch.matches.length; i++) {
|
|
const __mtch = mtch.__batch.matches[i];
|
|
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 += ` ${sqlLogicalOperator(mtch.__batch.operator || "OR")} `;
|
|
}
|
|
}
|
|
btch_mtch += `)`;
|
|
return {
|
|
str: btch_mtch,
|
|
values,
|
|
};
|
|
}
|
|
const equality = mtch.raw_equality
|
|
? sqlRawComparison(mtch.raw_equality)
|
|
: "=";
|
|
const lhs = typeof mtch.source == "object"
|
|
? columnRef(mtch.source.fieldName, mtch.source.tableName)
|
|
: columnRef(String(mtch.source), table_name);
|
|
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,
|
|
};
|
|
}
|
|
const rhs = (() => {
|
|
if (mtch.targetLiteral !== undefined && mtch.targetLiteral !== null) {
|
|
values.push(mtch.targetLiteral);
|
|
return `?`;
|
|
}
|
|
if (typeof mtch.target == "object") {
|
|
return columnRef(mtch.target.fieldName, mtch.target.tableName);
|
|
}
|
|
return columnRef(String(mtch.target), join.alias || join.tableName);
|
|
})();
|
|
return {
|
|
str: `${lhs} ${equality} ${rhs}`,
|
|
values,
|
|
};
|
|
}
|