MCPcopy
hub / github.com/BuilderIO/agent-native / getDbExec

Function getDbExec

packages/core/src/db/client.ts:486–513  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

484 * `execute()` call lazily initializes the underlying driver.
485 */
486export function getDbExec(): DbExec {
487 if (_exec) return _exec;
488
489 // Sanitize args: replace undefined with null (libsql rejects undefined)
490 function sanitize(
491 sql: string | { sql: string; args: any[] },
492 ): string | { sql: string; args: any[] } {
493 if (typeof sql === "object" && sql.args) {
494 return { ...sql, args: sql.args.map((a: any) => a ?? null) };
495 }
496 return sql;
497 }
498
499 // Return a proxy that lazy-inits on first call
500 const proxy: DbExec = {
501 async execute(sql) {
502 if (!_initPromise) _initPromise = initClient();
503 await _initPromise;
504 // After init, swap to a sanitizing wrapper around the real client
505 const wrapper: DbExec = {
506 execute: (s) => _exec!.execute(sanitize(s)),
507 };
508 Object.assign(proxy, wrapper);
509 return _exec!.execute(sanitize(sql));
510 },
511 };
512 return proxy;
513}
514
515/** Close the database connection (for scripts that need cleanup). */
516export async function closeDbExec(): Promise<void> {

Callers 15

requestOwnerRoleFunction · 0.90
db-health.tsFile · 0.90
update-slide.tsFile · 0.90
[id].patch.tsFile · 0.90
[id].delete.tsFile · 0.90
edit-document.tsFile · 0.90
list-comments.tsFile · 0.90
add-comment.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected