- 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]>
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
import sqlGenGrabConcatStr from "./sql-generator-grab-concat-str";
|
|
import { columnRef, quoteIdentifier } from "./sql-identifier";
|
|
export default function sqlGenGrabSelectFieldSQL({ selectFields, append_table_names, table_name }) {
|
|
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 = ``;
|
|
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 = fld_name;
|
|
}
|
|
if (fld.alias) {
|
|
fld_str += ` AS ${quoteIdentifier(fld.alias)}`;
|
|
}
|
|
return fld_str;
|
|
})
|
|
.join(",")}`;
|
|
}
|