File tree Expand file tree Collapse file tree 9 files changed +28
-9
lines changed Expand file tree Collapse file tree 9 files changed +28
-9
lines changed Original file line number Diff line number Diff line change 89
89
strategy :
90
90
matrix :
91
91
version :
92
- - 18.x
93
- - 20.x
92
+ - 18
93
+ - 20
94
94
runs-on : ubuntu-latest
95
95
needs : [build]
96
96
timeout-minutes : 3
@@ -138,10 +138,12 @@ jobs:
138
138
set -o pipefail
139
139
PGSSLMODE=disable node main.cjs | tee /dev/stderr | grep -q false
140
140
PGSSLMODE=require node main.cjs | tee /dev/stderr | grep -q true
141
+ [[ -d v$NODE_VERSION ]] && cd v$NODE_VERSION
141
142
npx tsc
142
143
PGSSLMODE=disable node main.mjs | tee /dev/stderr | grep -q false
143
144
PGSSLMODE=require node main.mjs | tee /dev/stderr | grep -q true
144
145
env :
146
+ NODE_VERSION : ${{ matrix.version }}
145
147
NODE_EXTRA_CA_CERTS : ${{ github.workspace }}/ssl-cert-snakeoil.pem
146
148
PGPORT : ${{ job.services.postgres.ports[5432] }}
147
149
PGUSER : postgres
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ In next release ...
4
4
connected when the promise returns. The ` Client ` symbol is now a
5
5
type instead of a value.
6
6
7
+ - Add ` [Symbol.asyncDispose] ` method to support [ Explicit Resource
8
+ Management] ( https://github.com/tc39/proposal-explicit-resource-management ) .
9
+
7
10
- Add ` off ` method to disable event listening.
8
11
9
12
- Remove dependency on
Original file line number Diff line number Diff line change 58
58
}
59
59
```
60
60
61
+ With TypeScript 5.2+ there is also support for ` await using ` :
62
+ ``` typescript
63
+ await using client = await connect ();
64
+ // Will be disposed of automatically at the end of the block.
65
+ ```
66
+
61
67
Waiting on the result (i.e., result iterator) returns the complete query result.
62
68
63
69
``` typescript
Original file line number Diff line number Diff line change 1
1
const { connect } = require ( 'ts-postgres' ) ;
2
- module . exports = connect ( ) . then ( ( client ) => {
2
+ module . exports = ( async ( ) => {
3
+ const client = await connect ( ) ;
3
4
console . log ( 'Encrypted: ' + client . encrypted ) ;
4
- return client . end ( ) ;
5
- } ) ;
5
+ await client . end ( ) ;
6
+ } ) ( ) ;
Original file line number Diff line number Diff line change 1
1
import { connect } from 'ts-postgres' ;
2
- const client = await connect ( ) ;
2
+ await using client = await connect ( ) ;
3
3
console . log ( 'Encrypted: ' + client . encrypted ) ;
4
- await client . end ( ) ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"devDependencies" : {
3
3
"@types/node" : " ^20.0" ,
4
- "typescript" : " ^4.8 "
4
+ "typescript" : " ^5.2 "
5
5
},
6
6
"dependencies" : {
7
7
"ts-postgres" : " ^2.0"
Original file line number Diff line number Diff line change
1
+ import { connect } from 'ts-postgres' ;
2
+ const client = await connect ( ) ;
3
+ console . log ( 'Encrypted: ' + client . encrypted ) ;
4
+ await client . end ( ) ;
Original file line number Diff line number Diff line change 27
27
},
28
28
"license" : " MIT" ,
29
29
"engines" : {
30
- "node" : " >=18.0.0 "
30
+ "node" : " >=18.0"
31
31
},
32
32
"scripts" : {
33
33
"lint" : " eslint -c .eslintrc.json --ext .ts src test" ,
Original file line number Diff line number Diff line change @@ -759,6 +759,10 @@ export class ClientImpl {
759
759
}
760
760
}
761
761
762
+ [ Symbol . asyncDispose ] ( ) {
763
+ return this . end ( ) ;
764
+ }
765
+
762
766
private send ( ) {
763
767
if ( this . mustDrain || ! this . connected ) return ;
764
768
this . sendUsing ( this . writer ) ;
You can’t perform that action at this time.
0 commit comments