mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
Add --sql-preconnect CLI flag for PostgreSQL startup connections (#21035)
Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: jarred-sumner-bot <220441119+jarred-sumner-bot@users.noreply.github.com> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com> Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
70ebe75e6c
commit
e9ccc81e03
@@ -308,6 +308,28 @@ pub const Run = struct {
|
||||
}
|
||||
}
|
||||
|
||||
do_postgres_preconnect: {
|
||||
if (this.ctx.runtime_options.sql_preconnect) {
|
||||
const global = vm.global;
|
||||
const bun_object = vm.global.toJSValue().get(global, "Bun") catch |err| {
|
||||
global.reportActiveExceptionAsUnhandled(err);
|
||||
break :do_postgres_preconnect;
|
||||
} orelse break :do_postgres_preconnect;
|
||||
const sql_object = bun_object.get(global, "sql") catch |err| {
|
||||
global.reportActiveExceptionAsUnhandled(err);
|
||||
break :do_postgres_preconnect;
|
||||
} orelse break :do_postgres_preconnect;
|
||||
const connect_fn = sql_object.get(global, "connect") catch |err| {
|
||||
global.reportActiveExceptionAsUnhandled(err);
|
||||
break :do_postgres_preconnect;
|
||||
} orelse break :do_postgres_preconnect;
|
||||
_ = connect_fn.call(global, sql_object, &.{}) catch |err| {
|
||||
global.reportActiveExceptionAsUnhandled(err);
|
||||
break :do_postgres_preconnect;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
switch (this.ctx.debug.hot_reload) {
|
||||
.hot => JSC.hot_reloader.HotReloader.enableHotModuleReloading(vm),
|
||||
.watch => JSC.hot_reloader.WatchReloader.enableHotModuleReloading(vm),
|
||||
|
||||
@@ -378,6 +378,7 @@ pub const Command = struct {
|
||||
debugger: Debugger = .{ .unspecified = {} },
|
||||
if_present: bool = false,
|
||||
redis_preconnect: bool = false,
|
||||
sql_preconnect: bool = false,
|
||||
eval: struct {
|
||||
script: []const u8 = "",
|
||||
eval_and_print: bool = false,
|
||||
|
||||
@@ -106,6 +106,7 @@ pub const runtime_params_ = [_]ParamType{
|
||||
clap.parseParam("--title <STR> Set the process title") catch unreachable,
|
||||
clap.parseParam("--zero-fill-buffers Boolean to force Buffer.allocUnsafe(size) to be zero-filled.") catch unreachable,
|
||||
clap.parseParam("--redis-preconnect Preconnect to $REDIS_URL at startup") catch unreachable,
|
||||
clap.parseParam("--sql-preconnect Preconnect to PostgreSQL at startup") catch unreachable,
|
||||
clap.parseParam("--no-addons Throw an error if process.dlopen is called, and disable export condition \"node-addons\"") catch unreachable,
|
||||
clap.parseParam("--unhandled-rejections <STR> One of \"strict\", \"throw\", \"warn\", \"none\", or \"warn-with-error-code\"") catch unreachable,
|
||||
clap.parseParam("--console-depth <NUMBER> Set the default depth for console.log object inspection (default: 2)") catch unreachable,
|
||||
@@ -589,6 +590,10 @@ pub fn parse(allocator: std.mem.Allocator, ctx: Command.Context, comptime cmd: C
|
||||
ctx.runtime_options.redis_preconnect = true;
|
||||
}
|
||||
|
||||
if (args.flag("--sql-preconnect")) {
|
||||
ctx.runtime_options.sql_preconnect = true;
|
||||
}
|
||||
|
||||
if (args.flag("--no-addons")) {
|
||||
// used for disabling process.dlopen and
|
||||
// for disabling export condition "node-addons"
|
||||
|
||||
Reference in New Issue
Block a user