@vibeorm/adapter-bun 5.0.2 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,7 +28,7 @@ await db.$disconnect();
28
28
 
29
29
  ## Options
30
30
 
31
- `bunAdapter(options: BunAdapterOptions)` — `url` is required. Without it, the factory throws `VIBE_CONFIG` (`meta.reason: "missing-address"`) before any driver instance or connection exists. The adapter never reads `DATABASE_URL` and always hands bun:sql this URL, so bun:sql's own `POSTGRES_URL` / `DATABASE_URL` / `PG*` lookup never chooses the server. A database named in the URL path is pinned explicitly, because bun:sql would otherwise let `PGDATABASE` replace it. Give a complete URL: bun:sql fills parts a URL leaves out (user, database, …) from the `PG*` variables.
31
+ `bunAdapter(options: BunAdapterOptions)` — `url` is required. Without it, the factory throws `VIBE_CONFIG` (`meta.reason: "missing-address"`) before any driver instance or connection exists. The adapter never reads `DATABASE_URL` and always hands bun:sql this URL, so bun:sql's own `POSTGRES_URL` / `DATABASE_URL` / `PG*` lookup never chooses the server. A database named in the URL path is pinned explicitly, because bun:sql would otherwise let `PGDATABASE` replace it. Give a complete URL: bun:sql fills parts a URL leaves out (user, database, …) from the `PG*` variables. `PGOPTIONS` works as in libpq and node-postgres: when the URL has no `options` parameter, it supplies the server settings, and the adapter's own `statementTimeout` and `planCacheMode` are added after it; a URL with `options` replaces it.
32
32
 
33
33
  | Option | Type | Default | Meaning |
34
34
  |---|---|---|---|
@@ -37,19 +37,19 @@ await db.$disconnect();
37
37
  | `min` | `number` | `0` | Connections `db.$connect()` reserves at once before it returns (at least one), so the first burst of parallel queries finds them ready instead of paying TCP + startup + authentication (on a far database about three round trips each — see adapter-pg's "A database far away"). bun:sql opens the pool's connections at its first use and closes none while idle, so they stay open. An integer from `0` through `max`; other values throw `VIBE_CONFIG` |
38
38
  | `statementTimeout` | `number` (ms) | — | Pool-wide `statement_timeout`, sent as a startup parameter so every connection inherits it; a per-transaction `timeout` overrides it |
39
39
  | `connectionTimeout` | `number` (ms) | URL `connect_timeout`, else none | Wait for a connection to be established. bun:sql expects seconds; the adapter converts |
40
- | `preparedStatements` | `boolean` | `false` | Use bun:sql's **named** prepared statements and run ORM-path queries as tagged templates (on Bun 1.4.3 and newer, a statement whose placeholders are `$1 … $n` in order binds by `$n` through `sql.unsafe`, which names it the same way). Off, every statement is an unnamed statement with text results — the node-postgres model. Read "Statements and values" before you turn it on |
40
+ | `preparedStatements` | `boolean` | `false` | Use bun:sql's **named** prepared statements and run ORM-path queries as tagged templates (a statement whose placeholders are `$1 … $n` in order binds by `$n` through `sql.unsafe`, which names it the same way). Off, every statement is an unnamed statement with text results — the node-postgres model. Read "Statements and values" before you turn it on |
41
41
  | `stmtCacheMax` | `number` | `1000` | Maximum entries in the synthetic template cache (LRU); used only with `preparedStatements: true` |
42
42
  | `planCacheMode` | `"auto" \| "force_custom_plan" \| "force_generic_plan"` | `"auto"` (nothing sent); `"force_custom_plan"` with `preparedStatements: true` | PostgreSQL `plan_cache_mode` for every connection |
43
43
 
44
44
  `planCacheMode` governs every plan the server caches on a connection: named statements, and also the plans of foreign-key checks, triggers and PL/pgSQL functions. An unnamed statement (the default mode) is planned for its own values whatever the setting says, so `force_custom_plan` there only made PostgreSQL replan the foreign-key check of every inserted row: `createMany` of 1000 rows took 20.3 ms with it and 16.2 ms without (adapter-pg, which sends no setting, 17.1 ms). With named statements the default stays `force_custom_plan`, so a named statement never switches to a generic plan after five executions.
45
45
 
46
- `planCacheMode` and `statementTimeout` merge into one `options` startup parameter, with adapter settings taking precedence over matching URL settings. Other URL settings are preserved. bun:sql forwards unrecognised URL parameters to the server, which rejects a client-side libpq option. The adapter therefore takes libpq's `connect_timeout` (whole seconds) out of the URL and uses it as `connectionTimeout`, so a URL written for node-postgres or `psql` connects here too; an explicit `connectionTimeout` option wins. Other client-side libpq options must not go in the URL. (The same forwarding is how a server setting reaches every connection: `?jit=off` on the URL disables JIT compilation for the pool — see `docs/dialect-notes.md` "PostgreSQL JIT and statistics".)
46
+ `planCacheMode` and `statementTimeout` merge into one `options` startup parameter, with adapter settings taking precedence over matching URL settings (or `PGOPTIONS` settings, for a URL without `options`). Other URL settings are preserved. bun:sql forwards unrecognised URL parameters to the server, which rejects a client-side libpq option. The adapter therefore takes libpq's `connect_timeout` (whole seconds) out of the URL and uses it as `connectionTimeout`, so a URL written for node-postgres or `psql` connects here too; an explicit `connectionTimeout` option wins. Other client-side libpq options must not go in the URL. (The same forwarding is how a server setting reaches every connection: `?jit=off` on the URL disables JIT compilation for the pool — see `docs/dialect-notes.md` "PostgreSQL JIT and statistics".)
47
47
 
48
- libpq's `sslrootcert=system` ("trust the CA roots of the system", as in PlanetScale's `?sslmode=verify-full&sslrootcert=system`) works as well. The adapter replaces it with `sslmode=verify-full`, so bun:sql verifies the server certificate's chain and host name against its default trust store (Bun's bundled roots plus `NODE_EXTRA_CA_CERTS`). Without that, Bun 1.4.1 forwards `sslrootcert` to the server, which refuses it, and Bun 1.4.4 lets `sslmode=verify-ca` stand next to it. As in libpq, an omitted `sslmode` means `verify-full`, and a weaker mode next to `sslrootcert=system` (also bun:sql's spellings such as `ssl=false`) is refused at construction with `VIBE_CONFIG` (`meta.reason: "sslrootcert-system-weak-sslmode"`).
48
+ libpq's `sslrootcert=system` ("trust the CA roots of the system", as in PlanetScale's `?sslmode=verify-full&sslrootcert=system`) works as well. The adapter replaces it with `sslmode=verify-full`, so bun:sql verifies the server certificate's chain and host name against its default trust store (Bun's bundled roots plus `NODE_EXTRA_CA_CERTS`). Without that, bun:sql lets `sslmode=verify-ca` stand next to it. As in libpq, an omitted `sslmode` means `verify-full`, and a weaker mode next to `sslrootcert=system` (also bun:sql's spellings such as `ssl=false`) is refused at construction with `VIBE_CONFIG` (`meta.reason: "sslrootcert-system-weak-sslmode"`).
49
49
 
50
50
  `connectionTimeout` does **not** bound waiting for a busy pool connection. The adapter therefore declares `budgets.acquireTimeout: false`. Newer Bun versions support cancellable explicit reservations, but implicit query and transaction checkout does not expose the same guarantee across supported versions. There is no timer race that leaves an abandoned checkout running.
51
51
 
52
- `Date` parameters are spelled as UTC ISO text on both paths: bun:sql's own serializer for a `date`-typed parameter is `Date#toString()`, which the server rejects in every host time zone. Zone-less columns (`@db.Timestamp(n)`, `@db.Date`) therefore hold the UTC wall-clock on write — the contract shared with node-postgres, PGlite and Prisma. On read, bun:sql is UTC from **Bun 1.4.1**; earlier Bun versions parse zone-less timestamp text as host-local time (1.3.x: scalars on parameterless statements and every array element; 1.4.0: array elements), and bun:sql has no per-query parser hook the adapter could use to correct it. On Bun < 1.4.1 keep the process on `TZ=UTC` when the schema has zone-less columns, or upgrade (`docs/dialect-notes.md` "DateTime without time zone on postgres").
52
+ `Date` parameters are spelled as UTC ISO text on both paths, so zone-less columns (`@db.Timestamp(n)`, `@db.Date`) hold the UTC wall-clock on write — the contract shared with node-postgres, PGlite and Prisma. On read, bun:sql parses zone-less timestamp text as UTC (`docs/dialect-notes.md` "DateTime without time zone on postgres").
53
53
 
54
54
  ## Statements and values
55
55
 
@@ -57,8 +57,8 @@ By default the adapter runs bun:sql with `prepare: false`: every statement is an
57
57
 
58
58
  `preparedStatements: true` switches bun:sql to **named** statements: one per SQL text per connection, pipelined, with results in the binary format for some types. On the repository benchmark (Bun 1.4.3, PostgreSQL 18, small scale, 27 scenarios, three interleaved rounds) the default mode, named mode and adapter-pg were within 3 % of each other (geometric mean of the median p50s); single rounds varied by up to 10 %, so there is no measured speed reason to turn named statements on where the database is local. Across a network, named mode saves round trips because Bun pipelines only named statements: transaction control (`BEGIN`, `SAVEPOINT`, a deadline bound) rides with the next read, and concurrent statements inside one transaction share a round trip (a one-read `$transaction` costs 2 round trips instead of 3; `tests/round-trip-wire.live.test.ts` pins both modes). Named mode also changes behaviour:
59
59
 
60
- - After DDL that changes a statement's result columns (`ALTER COLUMN … TYPE`, or `ADD COLUMN` under `SELECT *`), that statement fails with SQLSTATE `0A000` ("cached plan must not change result type") on every connection that prepared it, until the pool is replaced — measured on Bun 1.4.3. Bun 1.4.4-canary.1 re-prepares the statement and returns the row (`tests/node-postgres-parity.live.test.ts`). Run migrations with the application stopped, or restart it after. node-postgres named statements behave the same way.
61
- - `int4[]` and `float4[]` values with a NULL element or more than one dimension are refused by bun:sql (`ERR_POSTGRES_NULLS_IN_ARRAY_NOT_SUPPORTED_YET`, `ERR_POSTGRES_MULTIDIMENSIONAL_ARRAY_NOT_SUPPORTED_YET`).
60
+ - Each connection keeps its 1,024 most recently used statements; bun:sql closes the others on the server.
61
+ - After DDL that changes a statement's result columns (`ALTER COLUMN … TYPE`, or `ADD COLUMN` under `SELECT *`), bun:sql prepares the statement again on its next use and returns the row (`tests/node-postgres-parity.live.test.ts`). node-postgres named statements fail there with SQLSTATE `0A000` instead.
62
62
  - A string bound to a raw `::jsonb` slot is JSON-encoded again (see "Raw parameters").
63
63
  - A plain object bound to a raw slot that is not `json`/`jsonb` (for example `$1::text`) arrives as `[object Object]`; the default mode and node-postgres send its `JSON.stringify` text.
64
64
  - Named statements live on the **backend** connection, and bun:sql chooses their names itself: the collision-resistant, content-addressed names of `@vibeorm/adapter-pg` do not apply here. Supported setups are a direct connection, session pooling, and PgBouncer 1.21 or later in transaction mode with `max_prepared_statements` above 0 (PgBouncer then prepares each statement on the backend it links the client to). Behind any other transaction-mode pooler (Supavisor, Neon's pooler, PgBouncer before 1.21 or with `max_prepared_statements = 0`) a connection can reach a backend that does not hold its names, or holds another client's statement under the same name; keep the default unnamed mode there. In every setup, a statement prepared before a migration creates a same-named table earlier in the unchanged `search_path` keeps reading the old table until the pool is replaced.
@@ -80,7 +80,7 @@ With `preparedStatements: true`, bun:sql types each parameter by the OID the ser
80
80
 
81
81
  The last row is the limit: a slot whose type the server infers from its context (a column, a function argument) is not visible in the text, so bun:sql still JSON-encodes a string bound there. `::text::jsonb` is the spelling that is correct in every mode, and it is what the ORM path renders for every `Json` field (`jsonParamCast` in the postgres dialect); the ORM path is not respelled. A placeholder cast to `json` in one place and `jsonb` in another keeps its text too. A JSON array bound into a json column from raw SQL needs `JSON.stringify`, because a raw JS array is an array literal.
82
82
 
83
- Raw results are the driver's own values. bun:sql returns some types differently from node-postgres in raw queries: `uuid[]` and `citext[]` as the array-literal string (`"{…}"`), `interval`, `point` and `circle` as PostgreSQL's text (`"1 day 02:00:00"`, `"(1,2)"`; node-postgres returns objects), and `xid` as a number. The ORM path decodes list fields the same way on both adapters. One difference reaches the ORM path too: bun:sql reads a date or timestamp before year 1 (`BC`) as `Invalid Date`, where node-postgres returns the date.
83
+ Raw results are the driver's own values. bun:sql returns some types differently from node-postgres in raw queries: an array of an extension type such as `citext[]` as the array-literal string (`"{…}"`), `interval`, `point` and `circle` as PostgreSQL's text (`"1 day 02:00:00"`, `"(1,2)"`; node-postgres returns objects), and `xid` as a number. The ORM path decodes list fields the same way on both adapters.
84
84
 
85
85
  ## Session lifetime on `$disconnect()`
86
86
 
@@ -95,11 +95,11 @@ Two things that are NOT the adapter's doing but look like a leak:
95
95
 
96
96
  | Runtime | Supported |
97
97
  |---|---|
98
- | Bun ≥ 1.4.1 | yes |
99
- | Bun < 1.4.1 | no — `bunAdapter()` throws `VIBE_CONFIG` |
98
+ | Bun ≥ 1.4.4 | yes |
99
+ | Bun < 1.4.4 | no — `bunAdapter()` throws `VIBE_CONFIG` |
100
100
  | Node | no — `bun:sql` is a Bun built-in |
101
101
 
102
- Older bun:sql releases have data bugs the adapter cannot work around: on 1.3.14 a `COPY … TO STDOUT` hangs the connection, timestamps without a time zone are read in host-local time, `±infinity` dates become `Invalid Date`, and named statements could deliver one query's rows to another (fixed in Bun 1.4). 1.4.1, 1.4.2 and 1.4.3 pass the same probes. The repository's CI runs on the minimum version.
102
+ Older bun:sql releases have data bugs the adapter cannot work around. Up to 1.4.3, a BC date is read as `Invalid Date` and a 5-digit-year timestamp without a time zone in host-local time, and with `preparedStatements: true` no statement is ever closed on the server: every SQL text, and every combination of NULL parameters of one text, stays prepared on the backend for the connection's lifetime. On 1.3.14 a `COPY … TO STDOUT` also hangs the connection, `±infinity` dates become `Invalid Date`, and named statements could deliver one query's rows to another. The repository's CI runs on the minimum version.
103
103
 
104
104
  On Node, use [`@vibeorm/adapter-pg`](https://github.com/vibeorm/vibeorm/tree/master/packages/adapter-pg) instead; it speaks the same postgres dialect with the same semantics.
105
105
 
@@ -8,13 +8,4 @@
8
8
  export declare function refuseUnsupportedBun(params: {
9
9
  version: string;
10
10
  }): void;
11
- /**
12
- * Whether this Bun's `unsafe(text, values)` makes a NAMED statement on a
13
- * `prepare: true` instance ({@link NAMED_UNSAFE_BUN_VERSION} and newer), so
14
- * named mode can bind an ORM statement by `$n` instead of through a synthetic
15
- * tagged template (B-04).
16
- */
17
- export declare function namedUnsafeBinds(params: {
18
- version: string;
19
- }): boolean;
20
11
  //# sourceMappingURL=bun-version.d.ts.map
package/dist/config.d.ts CHANGED
@@ -1,18 +1,13 @@
1
1
  /**
2
- * Oldest Bun whose bun:sql the adapter accepts. Older releases — measured on
3
- * 1.3.14 with every adapter fix in place — hang after `COPY … TO STDOUT`,
4
- * read zone-less timestamps as host-local time and turn ±infinity dates into
5
- * `Invalid Date`; 1.4.1, 1.4.2 and 1.4.3 pass the same probes.
2
+ * Oldest Bun whose bun:sql the adapter accepts. 1.4.3 and older read a BC
3
+ * `timestamptz`/`date` as `Invalid Date` and a 5-digit-year `timestamp`
4
+ * without a time zone in host-local time, and with named statements
5
+ * (`preparedStatements: true`) never close a statement on the server: every
6
+ * SQL text, and every combination of NULL parameters of one text, stays
7
+ * prepared on the backend for the connection's lifetime. 1.3.14 also hangs
8
+ * after `COPY … TO STDOUT`. 1.4.4 passes the same probes.
6
9
  */
7
10
  export declare const MINIMUM_BUN_VERSION: string;
8
- /**
9
- * Oldest Bun on which `sql.unsafe(text, values)` on a `prepare: true` instance
10
- * was OBSERVED to create a NAMED statement and pipeline it like a tagged
11
- * template (performance audit round 2, B-04: wire capture on 1.4.3,
12
- * `Parse name="P…"`, then `B E H S` warm). Older supported versions keep the
13
- * synthetic templates: their `unsafe` behaviour was never measured.
14
- */
15
- export declare const NAMED_UNSAFE_BUN_VERSION: string;
16
11
  /**
17
12
  * PostgreSQL's limit on bound parameters in one statement (the Bind message
18
13
  * carries a 16-bit count).
@@ -13,11 +13,10 @@
13
13
  * still works here: {@link takeConnectTimeout} removes `connect_timeout` and
14
14
  * hands its seconds to bun:sql's `connectionTimeout` constructor option.
15
15
  *
16
- * libpq's `sslrootcert=system` (PlanetScale's URLs carry it) is the same
17
- * hazard on the minimum supported Bun: 1.4.1 forwards it as a startup
18
- * parameter (and without `sslmode` connects in plain text), while 1.4.4 reads
19
- * it but lets `sslmode=verify-ca` stand. {@link takeSystemRootCert} turns it
20
- * into `sslmode=verify-full` with libpq's rule on weaker modes.
16
+ * libpq's `sslrootcert=system` (PlanetScale's URLs carry it) needs the same
17
+ * care: bun:sql reads it but lets `sslmode=verify-ca` stand next to it.
18
+ * {@link takeSystemRootCert} turns it into `sslmode=verify-full` with libpq's
19
+ * rule on weaker modes.
21
20
  */
22
21
  /**
23
22
  * PostgreSQL plan-cache behaviour for every plan the server caches on the
@@ -88,9 +87,15 @@ export declare function takeConnectTimeout(params: {
88
87
  export declare function takeSystemRootCert(params: {
89
88
  url: string;
90
89
  }): string;
91
- /** Merge startup settings into one `options` key; adapter settings take precedence. */
90
+ /**
91
+ * Merge startup settings into one `options` key; adapter settings take
92
+ * precedence. The URL's own `options` come first. A URL without that key
93
+ * starts from `ambientOptions` (the `PGOPTIONS` environment variable), the
94
+ * rule of libpq and node-postgres — the adapter's settings never drop it.
95
+ */
92
96
  export declare function applyStartupOptions(params: {
93
97
  url: string;
94
98
  startupOptions: string;
99
+ ambientOptions?: string;
95
100
  }): string;
96
101
  //# sourceMappingURL=connection-url.d.ts.map
package/dist/index.d.ts CHANGED
@@ -12,12 +12,17 @@ import { type PlanCacheMode } from "./connection-url.ts";
12
12
  export type BunAdapterOptions = {
13
13
  /**
14
14
  * PostgreSQL connection URL — required. The adapter never reads
15
- * `DATABASE_URL` (or any other environment variable) itself, and always
16
- * hands bun:sql this URL, so bun's own environment lookup (`POSTGRES_URL`,
15
+ * `DATABASE_URL` or any other address variable itself, and always hands
16
+ * bun:sql this URL, so bun's own environment lookup (`POSTGRES_URL`,
17
17
  * `DATABASE_URL`, `PGHOST`, …) never chooses the server. A database named in
18
18
  * the URL path is pinned explicitly, because bun:sql would otherwise let
19
19
  * `PGDATABASE` replace it. Give a complete URL: bun:sql fills parts the URL
20
20
  * omits (user, database, …) from the `PG*` variables.
21
+ *
22
+ * `PGOPTIONS` works as in libpq and node-postgres: when the URL carries no
23
+ * `options` parameter, it supplies the server settings, and the adapter's
24
+ * own `statementTimeout` / `planCacheMode` are added after it (and win a
25
+ * conflict). A URL with `options` replaces it.
21
26
  */
22
27
  readonly url: string;
23
28
  /** Maximum pooled connections (default 10). */
@@ -51,17 +56,14 @@ export type BunAdapterOptions = {
51
56
  * results — bun:sql's `prepare: false`, the node-postgres model: values,
52
57
  * parameter typing and DDL behaviour match `@vibeorm/adapter-pg`.
53
58
  *
54
- * On, bun:sql keeps one named statement per SQL text per connection,
55
- * pipelines, and reads results in its binary format, with these driver
56
- * consequences (README "Statements and values"): a statement whose result
57
- * type a later DDL change alters fails with SQLSTATE 0A000 on that
58
- * connection until the pool is replaced (node-postgres named statements
59
- * behave the same); `int4[]`/`float4[]` values with NULL elements or more
60
- * than one dimension are refused. A raw JSON text string in an explicit
61
- * scalar json/jsonb cast is sent through text first; inferred JSON slots
62
- * retain Bun's JSON-string encoding. ORM-path queries also run as tagged
63
- * templates — on Bun 1.4.3 and newer only those whose placeholders are not
64
- * `$1 … $n` in order (the rest bind by `$n`, still named).
59
+ * On, bun:sql keeps named statements on each connection (its 1,024 most
60
+ * recently used), pipelines, and reads results in its binary format, with
61
+ * these driver consequences (README "Statements and values"): a statement
62
+ * whose result type a later DDL change alters is prepared again on its next
63
+ * use; a raw JSON text string in an explicit scalar json/jsonb cast is sent
64
+ * through text first; inferred JSON slots retain Bun's JSON-string
65
+ * encoding. ORM-path queries whose placeholders are not `$1 … $n` in order
66
+ * also run as tagged templates (the rest bind by `$n`, still named).
65
67
  */
66
68
  readonly preparedStatements?: boolean;
67
69
  /** Maximum entries in the synthetic template cache (default 1000, LRU). */
package/dist/index.js CHANGED
@@ -6,8 +6,7 @@ function createBunSql(params) {
6
6
  }
7
7
 
8
8
  // packages/adapter-bun/src/config.ts
9
- var MINIMUM_BUN_VERSION = "1.4.1";
10
- var NAMED_UNSAFE_BUN_VERSION = "1.4.3";
9
+ var MINIMUM_BUN_VERSION = "1.4.4";
11
10
  var MAX_BIND_PARAMETERS = 65535;
12
11
  var SESSION_CONNECTION = Object.freeze({
13
12
  max: 1,
@@ -21,13 +20,10 @@ function refuseUnsupportedBun(params) {
21
20
  return;
22
21
  throw new VibeError({
23
22
  code: "VIBE_CONFIG",
24
- message: `@vibeorm/adapter-bun requires Bun ${MINIMUM_BUN_VERSION} or newer (running ${params.version}): older bun:sql ` + "releases hang after COPY, read timestamps without a time zone in host-local time and turn infinity dates into Invalid Date. " + "Upgrade Bun, or use @vibeorm/adapter-pg.",
23
+ message: `@vibeorm/adapter-bun requires Bun ${MINIMUM_BUN_VERSION} or newer (running ${params.version}): older bun:sql ` + "releases read BC dates as Invalid Date and 5-digit-year timestamps without a time zone in host-local time, " + "and never close a named statement on the server. Upgrade Bun, or use @vibeorm/adapter-pg.",
25
24
  meta: { bunVersion: params.version, minimumBunVersion: MINIMUM_BUN_VERSION }
26
25
  });
27
26
  }
28
- function namedUnsafeBinds(params) {
29
- return Bun.semver.satisfies(params.version, `>=${NAMED_UNSAFE_BUN_VERSION}`);
30
- }
31
27
 
32
28
  // packages/adapter-bun/src/index.ts
33
29
  import { postgresDialect, renderDiagnostic } from "@vibeorm/sql";
@@ -140,7 +136,9 @@ function applyStartupOptions(params) {
140
136
  throw new VibeError2({ code: "VIBE_VALIDATION", message: "invalid PostgreSQL connection URL" });
141
137
  }
142
138
  const url = new URL(params.url);
143
- const merged = [...url.searchParams.getAll("options"), params.startupOptions].filter(Boolean).join(" ");
139
+ const own = url.searchParams.getAll("options");
140
+ const base = own.length > 0 ? own : [params.ambientOptions?.trim() ?? ""];
141
+ const merged = [...base, params.startupOptions].filter(Boolean).join(" ");
144
142
  url.searchParams.set("options", merged);
145
143
  url.search = url.searchParams.toString().replace(/\+/g, "%20");
146
144
  return url.toString();
@@ -685,8 +683,8 @@ function bunAdapter(options) {
685
683
  const usePrepared = options?.preparedStatements ?? false;
686
684
  const poolMin = options?.min === undefined ? 0 : assertPoolMin({ value: options.min, max: options?.max ?? 10 });
687
685
  const pipelining = usePrepared ? "batched" : "ordered";
688
- const namedUnsafe = usePrepared && namedUnsafeBinds({ version: Bun.version });
689
686
  const address = takeConnectTimeout({ url: takeSystemRootCert({ url: requireUrl({ options }) }) });
687
+ const ambientOptions = process.env.PGOPTIONS;
690
688
  const templates = createTemplateCache({ max: options?.stmtCacheMax ?? 1000 });
691
689
  const jsonText = usePrepared ? createJsonTextRespeller({ max: options?.stmtCacheMax ?? 1000 }) : null;
692
690
  let activeWire = WIRE_TEXT;
@@ -1149,7 +1147,7 @@ function bunAdapter(options) {
1149
1147
  planCacheMode: options?.planCacheMode ?? defaultPlanCacheMode({ preparedStatements: usePrepared }),
1150
1148
  statementTimeout: options?.statementTimeout
1151
1149
  });
1152
- const url = startupOptions === undefined ? address.url : applyStartupOptions({ url: address.url, startupOptions });
1150
+ const url = startupOptions === undefined ? address.url : applyStartupOptions({ url: address.url, startupOptions, ambientOptions });
1153
1151
  if (URL.canParse(url)) {
1154
1152
  const path = new URL(url).pathname;
1155
1153
  if (path.length > 1)
@@ -1213,7 +1211,7 @@ function bunAdapter(options) {
1213
1211
  const prepared = templates.getTemplate({ text: params.text });
1214
1212
  const identity = prepared.identityOrder && prepared.indices.length === values.length;
1215
1213
  const bound = identity ? values : bindTemplateValues({ text: params.text, indices: prepared.indices, values });
1216
- const result = bound.length > MAX_BIND_PARAMETERS || namedUnsafe && identity && values.length > 0 ? await runMapped(() => params.source.unsafe(params.text, values)) : await runMapped(() => params.source(prepared.template, ...bound));
1214
+ const result = bound.length > MAX_BIND_PARAMETERS || identity && values.length > 0 ? await runMapped(() => params.source.unsafe(params.text, values)) : await runMapped(() => params.source(prepared.template, ...bound));
1217
1215
  observeResult({ scope: params.scope, effect: params.effect, result });
1218
1216
  return plainRows({ rows: finalRows({ result }) });
1219
1217
  }
@@ -1904,4 +1902,4 @@ export {
1904
1902
  validateTransactionDeadline2 as validateTransactionDeadline
1905
1903
  };
1906
1904
 
1907
- //# debugId=B468C154EBB4425A64756E2164756E21
1905
+ //# debugId=EC0EB3CE1B302FCB64756E2164756E21