Bugfix: fix db-update return
This commit is contained in:
Vendored
+2
-21
@@ -65,33 +65,14 @@ export default async function DbUpdate({ table, data, query, targetId, config, }
|
|||||||
let updated_sql = ``;
|
let updated_sql = ``;
|
||||||
let updated_sql_values = [];
|
let updated_sql_values = [];
|
||||||
updated_sql += `SELECT * FROM ${quoteIdentifier(table)} ${whereClause}`;
|
updated_sql += `SELECT * FROM ${quoteIdentifier(table)} ${whereClause}`;
|
||||||
updated_sql_values = [...updated_sql_values, ...sqlQueryObj.values];
|
updated_sql_values = [...sqlQueryObj.values];
|
||||||
updated_sql += ` AND `;
|
|
||||||
for (let i = 0; i < keys.length; i++) {
|
|
||||||
const key = keys[i];
|
|
||||||
if (!key)
|
|
||||||
continue;
|
|
||||||
if (key == "updated_at")
|
|
||||||
continue;
|
|
||||||
const isLast = i == keys.length - 1;
|
|
||||||
updated_sql += ` ${quoteIdentifier(key)}=?`;
|
|
||||||
updated_sql_values.push(finalData[key] ?? null);
|
|
||||||
if (!isLast) {
|
|
||||||
updated_sql += ` AND `;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const updated_res = await dbHandler({
|
const updated_res = await dbHandler({
|
||||||
query: updated_sql,
|
query: updated_sql,
|
||||||
values: updated_sql_values,
|
values: updated_sql_values,
|
||||||
config,
|
config,
|
||||||
});
|
});
|
||||||
const affected_rows = updated_res.payload?.length;
|
|
||||||
return {
|
return {
|
||||||
...res,
|
...updated_res,
|
||||||
success: Boolean(affected_rows),
|
|
||||||
insert_return: {
|
|
||||||
affected_rows,
|
|
||||||
},
|
|
||||||
debug: {
|
debug: {
|
||||||
sqlObj,
|
sqlObj,
|
||||||
},
|
},
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/bun-mariadb",
|
"name": "@moduletrace/bun-mariadb",
|
||||||
"version": "1.0.13",
|
"version": "1.0.14",
|
||||||
"description": "Schema-driven MariaDB manager for Bun",
|
"description": "Schema-driven MariaDB manager for Bun",
|
||||||
"author": "Benjamin Toby",
|
"author": "Benjamin Toby",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -113,22 +113,7 @@ export default async function DbUpdate<
|
|||||||
let updated_sql_values: any[] = [];
|
let updated_sql_values: any[] = [];
|
||||||
|
|
||||||
updated_sql += `SELECT * FROM ${quoteIdentifier(table)} ${whereClause}`;
|
updated_sql += `SELECT * FROM ${quoteIdentifier(table)} ${whereClause}`;
|
||||||
updated_sql_values = [...updated_sql_values, ...sqlQueryObj.values];
|
updated_sql_values = [...sqlQueryObj.values];
|
||||||
updated_sql += ` AND `;
|
|
||||||
for (let i = 0; i < keys.length; i++) {
|
|
||||||
const key = keys[i];
|
|
||||||
if (!key) continue;
|
|
||||||
if (key == "updated_at") continue;
|
|
||||||
|
|
||||||
const isLast = i == keys.length - 1;
|
|
||||||
|
|
||||||
updated_sql += ` ${quoteIdentifier(key)}=?`;
|
|
||||||
updated_sql_values.push(finalData[key] ?? null);
|
|
||||||
|
|
||||||
if (!isLast) {
|
|
||||||
updated_sql += ` AND `;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const updated_res = await dbHandler({
|
const updated_res = await dbHandler({
|
||||||
query: updated_sql,
|
query: updated_sql,
|
||||||
@@ -136,14 +121,8 @@ export default async function DbUpdate<
|
|||||||
config,
|
config,
|
||||||
});
|
});
|
||||||
|
|
||||||
const affected_rows = updated_res.payload?.length;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...res,
|
...updated_res,
|
||||||
success: Boolean(affected_rows),
|
|
||||||
insert_return: {
|
|
||||||
affected_rows,
|
|
||||||
},
|
|
||||||
debug: {
|
debug: {
|
||||||
sqlObj,
|
sqlObj,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user