kysely-postgrejs 1.0.0 → 1.1.0

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/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  ## Changelog
2
2
 
3
- ### 1.0.0
3
+ ### [v1.1.0](https://github.com/panates/postgrejs-kysely/compare/v1.0.1...v1.1.0) -
4
+
5
+ #### 📖 Documentation Changes
6
+
7
+ - docs: keep the unspecified parameter types, and say what they cost @Eray Hanoğlu
8
+
9
+ ### [v1.0.1](https://github.com/panates/postgrejs-kysely/compare/v1.0.0...v1.0.1) - 20 September 2026
10
+
11
+ #### 📖 Documentation Changes
12
+
13
+ - docs: the suite passes outright, and the peer floor follows PostgreJS @Eray Hanoğlu
14
+
15
+ ### v1.0.0
4
16
 
5
17
  #### 🚀 New Features
6
18
 
package/README.md CHANGED
@@ -12,7 +12,7 @@ and query compiler are Kysely's own `Postgres*` implementations.
12
12
  npm install kysely-postgrejs kysely postgrejs
13
13
  ```
14
14
 
15
- `kysely` (>=0.29 <0.31) and `postgrejs` (>=3.6) are peer dependencies.
15
+ `kysely` (>=0.29 <0.31) and `postgrejs` (>=3.7) are peer dependencies.
16
16
 
17
17
  ## Usage
18
18
 
@@ -62,7 +62,7 @@ The pool you passed in is of course still yours to `acquire()` from directly as
62
62
  | `pool` | (required) | A PostgreJS `Pool`, or a function returning one. |
63
63
  | `fetchAsString` | - | OIDs to hand back as the server's own text. `[DataTypeOIDs.int8]` is how to get `pg`'s bigints. |
64
64
  | `fetchCount` | `4294967295` | How many rows a statement may return before the portal suspends. See below. |
65
- | `inferParameterTypes` | `true` | Whether PostgreSQL resolves each parameter's type from context, as it does for `pg`. |
65
+ | `inferParameterTypes` | `true` | Whether a `null` parameter is left for PostgreSQL to type from context. |
66
66
  | `prepare` | connection's own | Whether statements are cached as server-side prepared statements. `false` for PgBouncer. |
67
67
  | `rollbackOnError` | `false` | Whether a failed statement leaves the rest of the transaction usable. See below. |
68
68
  | `typeMap` | `GlobalTypeMap` | A custom `DataTypeMap`, to override how individual PostgreSQL types are decoded. |
@@ -79,19 +79,31 @@ queries; `streamQuery` ignores it and uses Kysely's `chunkSize` as the cursor's
79
79
 
80
80
  ### Why parameter types are left to the server
81
81
 
82
- PostgreJS gives every parameter a type OID taken from its JavaScript value, so a string arrives
83
- declared as `varchar`. That is a declaration, not a hint, and PostgreSQL stops inferring:
82
+ A parameter carrying a declared type is a parameter PostgreSQL will not coerce. Declare a string
83
+ `varchar` and it cannot go into a `json` column; declare a number `int4` and it cannot be coalesced
84
+ with a `varchar` column, compared against `jsonb`, or assigned into one:
85
+
86
+ ```
87
+ COALESCE types character varying and integer cannot be matched
88
+ operator does not exist: jsonb = integer
89
+ subscripted assignment to "data" requires type jsonb but expression is of type double precision
90
+ ```
91
+
92
+ `pg` sends type 0 - unspecified - for everything and lets the server resolve each parameter from
93
+ where it appears, so none of that surfaces there. The dialect does the same for strings, numbers,
94
+ booleans, bigints and nulls. Dates, buffers, arrays and objects keep PostgreJS's typed binary
95
+ encoders, since their text form is not something the server could parse out of context.
96
+
97
+ The cost is a parameter with no context at all: with neither a type nor anything to resolve
98
+ against, PostgreSQL settles on `text`.
84
99
 
85
100
  ```ts
86
- await db.insertInto('log').values({ payload: '{"a":1}' }).execute()
87
- // column "payload" is of type json but expression is of type character varying
101
+ await sql`select ${5} as v`.execute(db) // '5'
102
+ await sql`select ${5} + 1 as v`.execute(db) // 6 - the context decides
88
103
  ```
89
104
 
90
- `coalesce($1, 1)`, `$1 || name` and any call to an overloaded function fail the same way. `pg` sends
91
- type 0 - unspecified - and lets PostgreSQL resolve each parameter from where it appears, so none of
92
- this surfaces there. The dialect does the same by default. Only strings, numbers, booleans, bigints
93
- and nulls are affected; dates, buffers, arrays and objects keep PostgreJS's typed, binary encoding,
94
- which is both correct and faster. Set `inferParameterTypes: false` to declare types again.
105
+ That is the trade, and the three errors above are what the other side of it looks like.
106
+ `inferParameterTypes: false` declares types again.
95
107
 
96
108
  ### Getting `pg`'s bigints
97
109
 
@@ -158,19 +170,11 @@ one, and runs all of it:
158
170
  scripts/run-kysely-suite.sh
159
171
  ```
160
172
 
161
- Against Kysely v0.29.6: **683 passing, 1 failing**. Against v0.30.0-beta.2, the other end of the
162
- peer range: **727 passing, the same 1 failing**. For comparison, the same checkout against Kysely's
163
- own `pg` dialect passes 684 - the same tests, none of them skipped.
164
-
165
- The one failure asserts that the pool's last error reads "Connection terminated unexpectedly", which
166
- is `pg`'s wording after a killed session. PostgreJS 3.6 emits nothing at all there: it destroys the
167
- connection and opens another. The kill itself works - the test's own check that the query is gone
168
- passes first. PostgreJS has since grown a `ConnectionLostError` (SQLSTATE `08006`, carrying the
169
- backend's `processID`) that its pool reports on `'error'` and `'destroy'`, and with that build the
170
- suite passes all 684 - the same number as Kysely's own `pg` dialect. These numbers move to
171
- **684 / 0** and **728 / 0** when that release lands and the peer floor moves with it.
173
+ Against Kysely v0.29.6: **684 passing, nothing failing** - the same number Kysely's own `pg` dialect
174
+ scores on that checkout, with no test skipped. Against v0.30.0-beta.2, the other end of the peer
175
+ range: **728 passing, nothing failing**.
172
176
 
173
- Two other tests name the `pg` driver rather than describe behaviour: one asserts the error is an
177
+ Two of those tests name the `pg` driver rather than describe behaviour: one asserts the error is an
174
178
  instance of `pg`'s `DatabaseError`, and one stubs `PostgresDriver.prototype` and expects the stub to
175
179
  be called. The patch points both at this dialect's equivalents, which is what makes them test
176
180
  anything at all here - left alone they would pass over the behaviour without exercising it.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "kysely-postgrejs",
3
3
  "description": "Kysely dialect for PostgreJS - run a Kysely query builder on PostgreJS's wire-protocol client",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "author": "Panates",
6
6
  "license": "BSD-3-Clause",
7
7
  "peerDependencies": {
8
8
  "kysely": ">=0.29.0 <0.31.0",
9
- "postgrejs": ">=3.6.1 <4"
9
+ "postgrejs": ">=3.10.0 <4"
10
10
  },
11
11
  "type": "module",
12
12
  "module": "./index.js",
@@ -28,16 +28,16 @@ export interface PostgrejsDialectConfig {
28
28
  fetchCount?: number;
29
29
  /**
30
30
  * Whether each parameter's PostgreSQL type is left to the server to
31
- * resolve from where it appears in the query - what `pg` does, and what
32
- * Kysely's users therefore expect.
31
+ * resolve from where it appears, the way `pg` does.
33
32
  *
34
- * Defaults to `true`. PostgreJS otherwise declares a type derived from
35
- * the JavaScript value, which makes a string a `varchar` and breaks
36
- * every context where PostgreSQL would have inferred something else: a
37
- * `json` column, a `coalesce` of mixed types, `||`, an overloaded
38
- * function. Only strings, numbers, booleans, bigints and nulls are
39
- * affected - dates, buffers, arrays and objects keep PostgreJS's typed,
40
- * binary encoding either way.
33
+ * Defaults to `true`. A declared type is one PostgreSQL will not
34
+ * coerce: a string declared `varchar` cannot go into a `json` column,
35
+ * and a number declared `int4` cannot be coalesced with a `varchar`
36
+ * column, compared against `jsonb`, or assigned into one. Strings,
37
+ * numbers, booleans, bigints and nulls therefore go out unspecified;
38
+ * dates, buffers, arrays and objects keep PostgreJS's typed binary
39
+ * encoding. The cost is that a parameter with no context at all
40
+ * resolves to `text`, so `select $1` with a 5 answers `'5'`.
41
41
  */
42
42
  inferParameterTypes?: boolean;
43
43
  /**