Files
bun-sqlite/dist/lib/sqlite/db-delete.js
T
tbenandClaude Opus 5.5 938a1da71d Add queue tables, quote SQL identifiers (v1.3.0)
- isQueue table option adds queue columns and a (status, available_at)
  index; BunSQLite.queue exposes add, claim, complete, fail and
  release_stale with atomic claims
- Set busy_timeout on connections so workers in separate processes wait
  instead of failing with SQLITE_BUSY
- Quote table and column names with backticks in generated SQL, so
  reserved words (to, order, group) work and unknown columns error
  instead of matching as string literals
- Tests for queue ops, multi-process claims and reserved-word names

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 16:29:14 +01:00

55 lines
1.6 KiB
JavaScript

import dbHandler from "../db-handler";
import _ from "lodash";
import sqlGenerator from "../../utils/sql-generator";
import { sqlName } from "../../utils/sql-safe";
export default async function DbDelete({ table, query, targetId, config, }) {
let sqlObj = null;
try {
const finalQuery = query || {};
sqlObj = sqlGenerator({
tableName: table,
genObject: _.pick(finalQuery, ["query", "searchOperator"]),
targetId,
});
const whereClause = sqlObj.where.string;
if (whereClause) {
let sql = `DELETE FROM ${sqlName(table, "table name")} ${whereClause}`;
sqlObj.string = sql;
sqlObj.values = sqlObj.where.values;
const res = dbHandler({
query: sql,
values: sqlObj.values,
config,
});
if (!res.success) {
return { ...res, debug: { sqlObj } };
}
return {
success: Boolean(res.postInsertReturn?.affectedRows),
postInsertReturn: res.postInsertReturn,
debug: {
sqlObj,
},
};
}
else {
return {
success: false,
msg: `No WHERE clause`,
debug: {
sqlObj,
},
};
}
}
catch (error) {
return {
success: false,
error: error.message,
debug: {
sqlObj,
},
};
}
}