Add tests, schema sync safeguards, and query/handler improvements

- 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]>
This commit is contained in:
2026-10-14 02:27:59 +01:00
co-authored by Claude Opus 5.5
parent b81b09324a
commit ddf431e866
82 changed files with 2140 additions and 1403 deletions
+38 -45
View File
@@ -1,55 +1,48 @@
import sqlGenGrabConcatStr from "./sql-generator-grab-concat-str";
import { columnRef, quoteIdentifier } from "./sql-identifier";
export default function sqlGenGrabSelectFieldSQL({ selectFields, append_table_names, table_name }) {
let str = "";
str += ` ${selectFields
?.map((fld) => {
const table = append_table_names ? table_name : undefined;
return ` ${selectFields
.map((fld) => {
if (typeof fld != "object") {
return columnRef(String(fld), table);
}
const fld_name = columnRef(String(fld.fieldName), table);
let fld_str = ``;
const final_fld_name = typeof fld == "object"
? append_table_names
? `${table_name}.${String(fld)}`
: `${String(fld.fieldName)}`
: `${String(fld)}`;
if (typeof fld == "object") {
const fld_name = `${String(fld.fieldName)}`;
if (fld.count) {
fld_str += `COUNT(${fld_name})`;
}
else if (fld.sum) {
fld_str += `SUM(${fld_name})`;
}
else if (fld.average) {
fld_str += `AVERAGE(${fld_name})`;
}
else if (fld.max) {
fld_str += `MAX(${fld_name})`;
}
else if (fld.min) {
fld_str += `MIN(${fld_name})`;
}
else if (fld.distinct) {
fld_str += `DISTINCT ${fld_name}`;
}
else if (fld.group_concat) {
fld_str += sqlGenGrabConcatStr({
field: fld_name,
alias: fld.group_concat.alias,
separator: fld.group_concat.separator,
distinct: fld.group_concat.distinct,
});
}
else {
fld_str +=
final_fld_name + (fld.alias ? ` as ${fld.alias}` : ``);
}
if (fld.alias) {
fld_str += ` AS ${fld.alias}`;
}
if (fld.count) {
fld_str = `COUNT(${fld_name})`;
}
else if (fld.sum) {
fld_str = `SUM(${fld_name})`;
}
else if (fld.average) {
fld_str = `AVG(${fld_name})`;
}
else if (fld.max) {
fld_str = `MAX(${fld_name})`;
}
else if (fld.min) {
fld_str = `MIN(${fld_name})`;
}
else if (fld.distinct) {
fld_str = `DISTINCT ${fld_name}`;
}
else if (fld.group_concat) {
// Carries its own alias
return sqlGenGrabConcatStr({
field: fld_name,
alias: fld.group_concat.alias,
separator: fld.group_concat.separator,
distinct: fld.group_concat.distinct,
});
}
else {
fld_str += final_fld_name;
fld_str = fld_name;
}
if (fld.alias) {
fld_str += ` AS ${quoteIdentifier(fld.alias)}`;
}
return fld_str;
})
.join(",")}`;
return str;
}