@@ -300,15 +300,15 @@ const path = "/var/run/postgresql";
300
300
301
301
const client = new Client (
302
302
// postgres://user:password@%2Fvar%2Frun%2Fpostgresql:port/database_name
303
- ` postgres://user:password@${encodeURIComponent (path )}:port/database_name `
303
+ ` postgres://user:password@${encodeURIComponent (path )}:port/database_name ` ,
304
304
);
305
305
```
306
306
307
307
Additionally, you can specify the host using the ` host ` URL parameter
308
308
309
309
``` ts
310
310
const client = new Client (
311
- ` postgres://user:password@:port/database_name?host=/var/run/postgresql `
311
+ ` postgres://user:password@:port/database_name?host=/var/run/postgresql ` ,
312
312
);
313
313
```
314
314
@@ -355,7 +355,7 @@ const client = new Client({
355
355
tls: {
356
356
caCertificates: [
357
357
await Deno .readTextFile (
358
- new URL (" ./my_ca_certificate.crt" , import .meta .url )
358
+ new URL (" ./my_ca_certificate.crt" , import .meta .url ),
359
359
),
360
360
],
361
361
enabled: false ,
@@ -582,7 +582,7 @@ variables required, and then provide said variables in an array of arguments
582
582
{
583
583
const result = await client .queryArray (
584
584
" SELECT ID, NAME FROM PEOPLE WHERE AGE > $1 AND AGE < $2" ,
585
- [10 , 20 ]
585
+ [10 , 20 ],
586
586
);
587
587
console .log (result .rows );
588
588
}
@@ -605,7 +605,7 @@ replaced at runtime with an argument object
605
605
{
606
606
const result = await client .queryArray (
607
607
" SELECT ID, NAME FROM PEOPLE WHERE AGE > $MIN AND AGE < $MAX" ,
608
- { min: 10 , max: 20 }
608
+ { min: 10 , max: 20 },
609
609
);
610
610
console .log (result .rows );
611
611
}
@@ -632,7 +632,7 @@ places in your query
632
632
FROM PEOPLE
633
633
WHERE NAME ILIKE $SEARCH
634
634
OR LASTNAME ILIKE $SEARCH ` ,
635
- { search: " JACKSON" }
635
+ { search: " JACKSON" },
636
636
);
637
637
console .log (result .rows );
638
638
}
@@ -654,16 +654,16 @@ prepared statements with a nice and clear syntax for your queries
654
654
655
655
``` ts
656
656
{
657
- const result =
658
- await client .queryArray ` SELECT ID, NAME FROM PEOPLE WHERE AGE > ${10 } AND AGE < ${20 } ` ;
657
+ const result = await client
658
+ .queryArray ` SELECT ID, NAME FROM PEOPLE WHERE AGE > ${10 } AND AGE < ${20 } ` ;
659
659
console .log (result .rows );
660
660
}
661
661
662
662
{
663
663
const min = 10 ;
664
664
const max = 20 ;
665
- const result =
666
- await client .queryObject ` SELECT ID, NAME FROM PEOPLE WHERE AGE > ${min } AND AGE < ${max } ` ;
665
+ const result = await client
666
+ .queryObject ` SELECT ID, NAME FROM PEOPLE WHERE AGE > ${min } AND AGE < ${max } ` ;
667
667
console .log (result .rows );
668
668
}
669
669
```
@@ -712,7 +712,8 @@ await client.queryArray`UPDATE TABLE X SET Y = 0 WHERE Z = ${my_id}`;
712
712
// Invalid attempt to replace a specifier
713
713
const my_table = " IMPORTANT_TABLE" ;
714
714
const my_other_id = 41 ;
715
- await client .queryArray ` DELETE FROM ${my_table } WHERE MY_COLUMN = ${my_other_id }; ` ;
715
+ await client
716
+ .queryArray ` DELETE FROM ${my_table } WHERE MY_COLUMN = ${my_other_id }; ` ;
716
717
```
717
718
718
719
### Result decoding
@@ -752,7 +753,7 @@ available:
752
753
});
753
754
754
755
const result = await client .queryArray (
755
- " SELECT ID, NAME, AGE, BIRTHDATE FROM PEOPLE WHERE ID = 1"
756
+ " SELECT ID, NAME, AGE, BIRTHDATE FROM PEOPLE WHERE ID = 1" ,
756
757
);
757
758
console .log (result .rows ); // [[1, "Laura", 25, Date('1996-01-01') ]]
758
759
@@ -768,7 +769,7 @@ available:
768
769
});
769
770
770
771
const result = await client .queryArray (
771
- " SELECT ID, NAME, AGE, BIRTHDATE FROM PEOPLE WHERE ID = 1"
772
+ " SELECT ID, NAME, AGE, BIRTHDATE FROM PEOPLE WHERE ID = 1" ,
772
773
);
773
774
console .log (result .rows ); // [["1", "Laura", "25", "1996-01-01"]]
774
775
}
@@ -804,7 +805,7 @@ the strategy and internal decoders.
804
805
});
805
806
806
807
const result = await client .queryObject (
807
- " SELECT ID, NAME, IS_ACTIVE FROM PEOPLE"
808
+ " SELECT ID, NAME, IS_ACTIVE FROM PEOPLE" ,
808
809
);
809
810
console .log (result .rows [0 ]);
810
811
// {id: '1', name: 'Javier', is_active: { value: false, type: "boolean"}}
@@ -833,7 +834,7 @@ for the array type itself.
833
834
});
834
835
835
836
const result = await client .queryObject (
836
- " SELECT ARRAY[ 2, 2, 3, 1 ] AS scores, 8 final_score;"
837
+ " SELECT ARRAY[ 2, 2, 3, 1 ] AS scores, 8 final_score;" ,
837
838
);
838
839
console .log (result .rows [0 ]);
839
840
// { scores: [ 200, 200, 300, 100 ], final_score: 800 }
@@ -849,7 +850,7 @@ IntelliSense
849
850
``` ts
850
851
{
851
852
const array_result = await client .queryArray <[number , string ]>(
852
- " SELECT ID, NAME FROM PEOPLE WHERE ID = 17"
853
+ " SELECT ID, NAME FROM PEOPLE WHERE ID = 17" ,
853
854
);
854
855
// [number, string]
855
856
const person = array_result .rows [0 ];
@@ -865,7 +866,7 @@ IntelliSense
865
866
866
867
{
867
868
const object_result = await client .queryObject <{ id: number ; name: string }>(
868
- " SELECT ID, NAME FROM PEOPLE WHERE ID = 17"
869
+ " SELECT ID, NAME FROM PEOPLE WHERE ID = 17" ,
869
870
);
870
871
// {id: number, name: string}
871
872
const person = object_result .rows [0 ];
@@ -930,7 +931,7 @@ one the user might expect
930
931
931
932
``` ts
932
933
const result = await client .queryObject (
933
- " SELECT ID, SUBSTR(NAME, 0, 2) FROM PEOPLE"
934
+ " SELECT ID, SUBSTR(NAME, 0, 2) FROM PEOPLE" ,
934
935
);
935
936
936
937
const users = result .rows ; // [{id: 1, substr: 'Ca'}, {id: 2, substr: 'Jo'}, ...]
@@ -958,7 +959,7 @@ interface User {
958
959
}
959
960
960
961
const result = await client .queryObject <User >(
961
- " SELECT ID, SUBSTR(NAME, 0, 2) FROM PEOPLE"
962
+ " SELECT ID, SUBSTR(NAME, 0, 2) FROM PEOPLE" ,
962
963
);
963
964
964
965
const users = result .rows ; // TypeScript says this will be User[]
@@ -1183,7 +1184,8 @@ const transaction = client_1.createTransaction("transaction_1");
1183
1184
1184
1185
await transaction .begin ();
1185
1186
1186
- await transaction .queryArray ` CREATE TABLE TEST_RESULTS (USER_ID INTEGER, GRADE NUMERIC(10,2)) ` ;
1187
+ await transaction
1188
+ .queryArray ` CREATE TABLE TEST_RESULTS (USER_ID INTEGER, GRADE NUMERIC(10,2)) ` ;
1187
1189
await transaction .queryArray ` CREATE TABLE GRADUATED_STUDENTS (USER_ID INTEGER) ` ;
1188
1190
1189
1191
// This operation takes several minutes
@@ -1239,7 +1241,8 @@ following levels of transaction isolation:
1239
1241
const password_1 = rows [0 ].password ;
1240
1242
1241
1243
// Concurrent operation executed by a different user in a different part of the code
1242
- await client_2 .queryArray ` UPDATE IMPORTANT_TABLE SET PASSWORD = 'something_else' WHERE ID = ${the_same_id } ` ;
1244
+ await client_2
1245
+ .queryArray ` UPDATE IMPORTANT_TABLE SET PASSWORD = 'something_else' WHERE ID = ${the_same_id } ` ;
1243
1246
1244
1247
const { rows : query_2 } = await transaction .queryObject <{
1245
1248
password: string ;
@@ -1277,12 +1280,14 @@ following levels of transaction isolation:
1277
1280
}>` SELECT PASSWORD FROM IMPORTANT_TABLE WHERE ID = ${my_id } ` ;
1278
1281
1279
1282
// Concurrent operation executed by a different user in a different part of the code
1280
- await client_2 .queryArray ` UPDATE IMPORTANT_TABLE SET PASSWORD = 'something_else' WHERE ID = ${the_same_id } ` ;
1283
+ await client_2
1284
+ .queryArray ` UPDATE IMPORTANT_TABLE SET PASSWORD = 'something_else' WHERE ID = ${the_same_id } ` ;
1281
1285
1282
1286
// This statement will throw
1283
1287
// Target was modified outside of the transaction
1284
1288
// User may not be aware of the changes
1285
- await transaction .queryArray ` UPDATE IMPORTANT_TABLE SET PASSWORD = 'shiny_new_password' WHERE ID = ${the_same_id } ` ;
1289
+ await transaction
1290
+ .queryArray ` UPDATE IMPORTANT_TABLE SET PASSWORD = 'shiny_new_password' WHERE ID = ${the_same_id } ` ;
1286
1291
1287
1292
// Transaction is aborted, no need to end it
1288
1293
@@ -1419,7 +1424,7 @@ explained above in the `Savepoint` documentation.
1419
1424
1420
1425
``` ts
1421
1426
const transaction = client .createTransaction (
1422
- " partially_rolled_back_transaction"
1427
+ " partially_rolled_back_transaction" ,
1423
1428
);
1424
1429
await transaction .savepoint (" undo" );
1425
1430
await transaction .queryArray ` TRUNCATE TABLE DONT_DELETE_ME ` ; // Oops, wrong table
0 commit comments