Fix silent exit when a query runs on a connection left idle by a prompt
An idle Bun.SQL connection does not keep the event loop alive. After an inquirer prompt released stdin, the next query let Bun exit with code 0 mid-query: `schema` never applied confirmed destructive changes, and `admin` table views exited instead of showing results. Hold the loop open for the duration of every query and transaction. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Vendored
+3
-3
@@ -1,4 +1,4 @@
|
||||
import dbHandler, { resolveClient } from "../db-handler";
|
||||
import dbHandler, { holdEventLoop, resolveClient } from "../db-handler";
|
||||
import sqlGenerator from "../../utils/sql-generator";
|
||||
import sanitizeHtmlFields from "../../utils/sanitize-html-fields";
|
||||
import { quoteIdentifier } from "../../utils/sql-identifier";
|
||||
@@ -62,7 +62,7 @@ export default async function DbUpdate({ table, data, query, targetId, config, }
|
||||
* all in one transaction. Re-fetching by id still works when the update
|
||||
* changes a column used in the WHERE clause.
|
||||
*/
|
||||
return await CLIENT.begin(async (tx) => {
|
||||
return await holdEventLoop(() => CLIENT.begin(async (tx) => {
|
||||
const matched_res = await dbHandler({
|
||||
query: `SELECT id FROM ${quoteIdentifier(table)} ${whereClause} FOR UPDATE`,
|
||||
values: sqlQueryObj.whereValues,
|
||||
@@ -111,7 +111,7 @@ export default async function DbUpdate({ table, data, query, targetId, config, }
|
||||
},
|
||||
db_res: res.db_res,
|
||||
};
|
||||
});
|
||||
}));
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof UpdateAbort) {
|
||||
|
||||
Reference in New Issue
Block a user