Files
bun-mariadb/dist/lib/db-handler.d.ts
T
tbenandClaude Opus 5.5 688f4bcb58 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]>
2026-10-16 06:18:59 +01:00

34 lines
1.2 KiB
TypeScript

import type { BunMariaDBConfig, DBResponseObject } from "../types";
/** Anything that can run a raw query: a client or a transaction handle */
export type DBQueryRunner = {
unsafe: (query: string, values?: any[]) => Promise<any>;
};
type Param = {
query: string;
values?: any[];
config?: BunMariaDBConfig;
/** Run on this client / transaction instead of the shared client */
client?: DBQueryRunner;
};
/**
* Resolve a shared MariaDB client. Prefer the global client so schema sync
* and CRUD do not open a new connection per query.
*/
export declare function resolveClient(config?: BunMariaDBConfig): Bun.SQL | undefined;
/**
* Keep the event loop alive until `fn` settles.
* An idle Bun.SQL connection does not hold the process open, so a query sent
* on it after something else released the loop (e.g. an inquirer prompt
* releasing stdin) lets Bun exit silently mid-query.
*/
export declare function holdEventLoop<T>(fn: () => Promise<T>): Promise<T>;
/**
* # Main DB Handler Function
*/
export default function dbHandler<T extends {
[k: string]: any;
} = {
[k: string]: any;
}>({ query, values, config, client }: Param): Promise<DBResponseObject<T>>;
export {};