mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
SQLite in Bun.sql (#21640)
### What does this PR do? Support sqlite in the Bun.sql API Fixes #18951 Fixes #19701 ### How did you verify your code works? tests --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
@@ -213,13 +213,13 @@ pub fn onConnectionTimeout(this: *PostgresSQLConnection) bun.api.Timer.EventLoop
|
||||
|
||||
switch (this.status) {
|
||||
.connected => {
|
||||
this.failFmt(.POSTGRES_IDLE_TIMEOUT, "Idle timeout reached after {}", .{bun.fmt.fmtDurationOneDecimal(@as(u64, this.idle_timeout_interval_ms) *| std.time.ns_per_ms)});
|
||||
this.failFmt("ERR_POSTGRES_IDLE_TIMEOUT", "Idle timeout reached after {}", .{bun.fmt.fmtDurationOneDecimal(@as(u64, this.idle_timeout_interval_ms) *| std.time.ns_per_ms)});
|
||||
},
|
||||
else => {
|
||||
this.failFmt(.POSTGRES_CONNECTION_TIMEOUT, "Connection timeout after {}", .{bun.fmt.fmtDurationOneDecimal(@as(u64, this.connection_timeout_ms) *| std.time.ns_per_ms)});
|
||||
this.failFmt("ERR_POSTGRES_CONNECTION_TIMEOUT", "Connection timeout after {}", .{bun.fmt.fmtDurationOneDecimal(@as(u64, this.connection_timeout_ms) *| std.time.ns_per_ms)});
|
||||
},
|
||||
.sent_startup_message => {
|
||||
this.failFmt(.POSTGRES_CONNECTION_TIMEOUT, "Connection timed out after {} (sent startup message, but never received response)", .{bun.fmt.fmtDurationOneDecimal(@as(u64, this.connection_timeout_ms) *| std.time.ns_per_ms)});
|
||||
this.failFmt("ERR_POSTGRES_CONNECTION_TIMEOUT", "Connection timed out after {} (sent startup message, but never received response)", .{bun.fmt.fmtDurationOneDecimal(@as(u64, this.connection_timeout_ms) *| std.time.ns_per_ms)});
|
||||
},
|
||||
}
|
||||
return .disarm;
|
||||
@@ -229,7 +229,7 @@ pub fn onMaxLifetimeTimeout(this: *PostgresSQLConnection) bun.api.Timer.EventLoo
|
||||
debug("onMaxLifetimeTimeout", .{});
|
||||
this.max_lifetime_timer.state = .FIRED;
|
||||
if (this.status == .failed) return .disarm;
|
||||
this.failFmt(.POSTGRES_LIFETIME_TIMEOUT, "Max lifetime timeout reached after {}", .{bun.fmt.fmtDurationOneDecimal(@as(u64, this.max_lifetime_interval_ms) *| std.time.ns_per_ms)});
|
||||
this.failFmt("ERR_POSTGRES_LIFETIME_TIMEOUT", "Max lifetime timeout reached after {}", .{bun.fmt.fmtDurationOneDecimal(@as(u64, this.max_lifetime_interval_ms) *| std.time.ns_per_ms)});
|
||||
return .disarm;
|
||||
}
|
||||
|
||||
@@ -332,8 +332,13 @@ pub fn failWithJSValue(this: *PostgresSQLConnection, value: JSValue) void {
|
||||
) catch |e| this.globalObject.reportActiveExceptionAsUnhandled(e);
|
||||
}
|
||||
|
||||
pub fn failFmt(this: *PostgresSQLConnection, comptime error_code: jsc.Error, comptime fmt: [:0]const u8, args: anytype) void {
|
||||
this.failWithJSValue(error_code.fmt(this.globalObject, fmt, args));
|
||||
pub fn failFmt(this: *PostgresSQLConnection, code: []const u8, comptime fmt: [:0]const u8, args: anytype) void {
|
||||
const message = std.fmt.allocPrint(bun.default_allocator, fmt, args) catch bun.outOfMemory();
|
||||
defer bun.default_allocator.free(message);
|
||||
|
||||
const err = createPostgresError(this.globalObject, message, .{ .code = code }) catch |e| this.globalObject.takeError(e);
|
||||
|
||||
this.failWithJSValue(err);
|
||||
}
|
||||
|
||||
pub fn fail(this: *PostgresSQLConnection, message: []const u8, err: AnyPostgresError) void {
|
||||
@@ -1825,6 +1830,7 @@ const Status = @import("./Status.zig").Status;
|
||||
const TLSStatus = @import("./TLSStatus.zig").TLSStatus;
|
||||
|
||||
const AnyPostgresError = @import("./AnyPostgresError.zig").AnyPostgresError;
|
||||
const createPostgresError = @import("./AnyPostgresError.zig").createPostgresError;
|
||||
const postgresErrorToJS = @import("./AnyPostgresError.zig").postgresErrorToJS;
|
||||
|
||||
const bun = @import("bun");
|
||||
|
||||
Reference in New Issue
Block a user