From a512ad515586643fdd10dcbec51eda3495543be8 Mon Sep 17 00:00:00 2001 From: Ciro Spaciari Date: Mon, 21 Apr 2025 22:21:55 -0700 Subject: [PATCH] fix(sql) fix flush (#19177) --- src/bun.js/api/postgres.classes.ts | 3 +++ src/sql/postgres.zig | 4 ++++ test/js/sql/sql.test.ts | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/src/bun.js/api/postgres.classes.ts b/src/bun.js/api/postgres.classes.ts index 136c0dd09b..3e7e8706a2 100644 --- a/src/bun.js/api/postgres.classes.ts +++ b/src/bun.js/api/postgres.classes.ts @@ -29,6 +29,9 @@ export default [ unref: { fn: "doUnref", }, + flush: { + fn: "doFlush", + }, queries: { getter: "getQueries", diff --git a/src/sql/postgres.zig b/src/sql/postgres.zig index 9b5c76309c..9d3ff8548c 100644 --- a/src/sql/postgres.zig +++ b/src/sql/postgres.zig @@ -2057,6 +2057,10 @@ pub const PostgresSQLConnection = struct { this.updateHasPendingActivity(); return .undefined; } + pub fn doFlush(this: *PostgresSQLConnection, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue { + this.flushData(); + return .undefined; + } pub fn deref(this: *@This()) void { const ref_count = this.ref_count; diff --git a/test/js/sql/sql.test.ts b/test/js/sql/sql.test.ts index c022e19246..b904c144d2 100644 --- a/test/js/sql/sql.test.ts +++ b/test/js/sql/sql.test.ts @@ -2255,6 +2255,12 @@ if (isDockerEnabled()) { expect(result).toBe("1.2"); }); + test("flush should work", async () => { + await using sql = postgres(options); + await sql`select 1`; + sql.flush(); + }); + // t('Async stack trace', async() => { // const sql = postgres({ ...options, debug: false }) // return [