11# deno-postgres
22
33![ Build Status] ( https://img.shields.io/github/actions/workflow/status/denodrivers/postgres/ci.yml?branch=main&label=Build&logo=github&style=flat-square )
4- [ ![ Discord server] ( https://img.shields.io/discord/768918486575480863?color=blue&label=Ask%20for%20help%20here&logo=discord&style=flat-square )] ( https://discord.gg/HEdTCvZUSf )
4+ [ ![ Discord server] ( https://img.shields.io/discord/768918486575480863?color=blue&label=Ask%20for%20help%20here&logo=discord&style=flat-square )] ( https://discord.gg/sCNaAvQeEa )
55[ ![ JSR] ( https://jsr.io/badges/@db/postgres?style=flat-square )] ( https://jsr.io/@db/postgres )
66[ ![ JSR Score] ( https://jsr.io/badges/@db/postgres/score?style=flat-square )] ( https://jsr.io/@db/postgres )
77[ ![ Manual] ( https://img.shields.io/github/v/release/denodrivers/postgres?color=orange&label=Manual&logo=deno&style=flat-square )] ( https://deno-postgres.com )
@@ -300,15 +300,15 @@ const path = "/var/run/postgresql";
300300
301301const client = new Client (
302302 // 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 `
304304);
305305```
306306
307307Additionally, you can specify the host using the ` host ` URL parameter
308308
309309``` ts
310310const 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 `
312312);
313313```
314314
@@ -355,7 +355,7 @@ const client = new Client({
355355 tls: {
356356 caCertificates: [
357357 await Deno .readTextFile (
358- new URL (" ./my_ca_certificate.crt" , import .meta .url ),
358+ new URL (" ./my_ca_certificate.crt" , import .meta .url )
359359 ),
360360 ],
361361 enabled: false ,
@@ -582,7 +582,7 @@ variables required, and then provide said variables in an array of arguments
582582{
583583 const result = await client .queryArray (
584584 " SELECT ID, NAME FROM PEOPLE WHERE AGE > $1 AND AGE < $2" ,
585- [10 , 20 ],
585+ [10 , 20 ]
586586 );
587587 console .log (result .rows );
588588}
@@ -605,7 +605,7 @@ replaced at runtime with an argument object
605605{
606606 const result = await client .queryArray (
607607 " SELECT ID, NAME FROM PEOPLE WHERE AGE > $MIN AND AGE < $MAX" ,
608- { min: 10 , max: 20 },
608+ { min: 10 , max: 20 }
609609 );
610610 console .log (result .rows );
611611}
@@ -632,7 +632,7 @@ places in your query
632632 FROM PEOPLE
633633 WHERE NAME ILIKE $SEARCH
634634 OR LASTNAME ILIKE $SEARCH ` ,
635- { search: " JACKSON" },
635+ { search: " JACKSON" }
636636 );
637637 console .log (result .rows );
638638}
@@ -654,16 +654,16 @@ prepared statements with a nice and clear syntax for your queries
654654
655655``` ts
656656{
657- const result = await client
658- .queryArray ` SELECT ID, NAME FROM PEOPLE WHERE AGE > ${10 } AND AGE < ${20 } ` ;
657+ const result =
658+ await client .queryArray ` SELECT ID, NAME FROM PEOPLE WHERE AGE > ${10 } AND AGE < ${20 } ` ;
659659 console .log (result .rows );
660660}
661661
662662{
663663 const min = 10 ;
664664 const max = 20 ;
665- const result = await client
666- .queryObject ` SELECT ID, NAME FROM PEOPLE WHERE AGE > ${min } AND AGE < ${max } ` ;
665+ const result =
666+ await client .queryObject ` SELECT ID, NAME FROM PEOPLE WHERE AGE > ${min } AND AGE < ${max } ` ;
667667 console .log (result .rows );
668668}
669669```
@@ -712,8 +712,7 @@ await client.queryArray`UPDATE TABLE X SET Y = 0 WHERE Z = ${my_id}`;
712712// Invalid attempt to replace a specifier
713713const my_table = " IMPORTANT_TABLE" ;
714714const my_other_id = 41 ;
715- await client
716- .queryArray ` DELETE FROM ${my_table } WHERE MY_COLUMN = ${my_other_id }; ` ;
715+ await client .queryArray ` DELETE FROM ${my_table } WHERE MY_COLUMN = ${my_other_id }; ` ;
717716```
718717
719718### Result decoding
@@ -753,7 +752,7 @@ available:
753752 });
754753
755754 const result = await client .queryArray (
756- " SELECT ID, NAME, AGE, BIRTHDATE FROM PEOPLE WHERE ID = 1" ,
755+ " SELECT ID, NAME, AGE, BIRTHDATE FROM PEOPLE WHERE ID = 1"
757756 );
758757 console .log (result .rows ); // [[1, "Laura", 25, Date('1996-01-01') ]]
759758
@@ -769,7 +768,7 @@ available:
769768 });
770769
771770 const result = await client .queryArray (
772- " SELECT ID, NAME, AGE, BIRTHDATE FROM PEOPLE WHERE ID = 1" ,
771+ " SELECT ID, NAME, AGE, BIRTHDATE FROM PEOPLE WHERE ID = 1"
773772 );
774773 console .log (result .rows ); // [["1", "Laura", "25", "1996-01-01"]]
775774}
@@ -805,7 +804,7 @@ the strategy and internal decoders.
805804 });
806805
807806 const result = await client .queryObject (
808- " SELECT ID, NAME, IS_ACTIVE FROM PEOPLE" ,
807+ " SELECT ID, NAME, IS_ACTIVE FROM PEOPLE"
809808 );
810809 console .log (result .rows [0 ]);
811810 // {id: '1', name: 'Javier', is_active: { value: false, type: "boolean"}}
@@ -834,7 +833,7 @@ for the array type itself.
834833 });
835834
836835 const result = await client .queryObject (
837- " SELECT ARRAY[ 2, 2, 3, 1 ] AS scores, 8 final_score;" ,
836+ " SELECT ARRAY[ 2, 2, 3, 1 ] AS scores, 8 final_score;"
838837 );
839838 console .log (result .rows [0 ]);
840839 // { scores: [ 200, 200, 300, 100 ], final_score: 800 }
@@ -850,7 +849,7 @@ IntelliSense
850849``` ts
851850{
852851 const array_result = await client .queryArray <[number , string ]>(
853- " SELECT ID, NAME FROM PEOPLE WHERE ID = 17" ,
852+ " SELECT ID, NAME FROM PEOPLE WHERE ID = 17"
854853 );
855854 // [number, string]
856855 const person = array_result .rows [0 ];
@@ -866,7 +865,7 @@ IntelliSense
866865
867866{
868867 const object_result = await client .queryObject <{ id: number ; name: string }>(
869- " SELECT ID, NAME FROM PEOPLE WHERE ID = 17" ,
868+ " SELECT ID, NAME FROM PEOPLE WHERE ID = 17"
870869 );
871870 // {id: number, name: string}
872871 const person = object_result .rows [0 ];
@@ -931,7 +930,7 @@ one the user might expect
931930
932931``` ts
933932const result = await client .queryObject (
934- " SELECT ID, SUBSTR(NAME, 0, 2) FROM PEOPLE" ,
933+ " SELECT ID, SUBSTR(NAME, 0, 2) FROM PEOPLE"
935934);
936935
937936const users = result .rows ; // [{id: 1, substr: 'Ca'}, {id: 2, substr: 'Jo'}, ...]
@@ -959,7 +958,7 @@ interface User {
959958}
960959
961960const result = await client .queryObject <User >(
962- " SELECT ID, SUBSTR(NAME, 0, 2) FROM PEOPLE" ,
961+ " SELECT ID, SUBSTR(NAME, 0, 2) FROM PEOPLE"
963962);
964963
965964const users = result .rows ; // TypeScript says this will be User[]
@@ -1184,8 +1183,7 @@ const transaction = client_1.createTransaction("transaction_1");
11841183
11851184await transaction .begin ();
11861185
1187- await transaction
1188- .queryArray ` CREATE TABLE TEST_RESULTS (USER_ID INTEGER, GRADE NUMERIC(10,2)) ` ;
1186+ await transaction .queryArray ` CREATE TABLE TEST_RESULTS (USER_ID INTEGER, GRADE NUMERIC(10,2)) ` ;
11891187await transaction .queryArray ` CREATE TABLE GRADUATED_STUDENTS (USER_ID INTEGER) ` ;
11901188
11911189// This operation takes several minutes
@@ -1241,8 +1239,7 @@ following levels of transaction isolation:
12411239 const password_1 = rows [0 ].password ;
12421240
12431241 // Concurrent operation executed by a different user in a different part of the code
1244- await client_2
1245- .queryArray ` UPDATE IMPORTANT_TABLE SET PASSWORD = 'something_else' WHERE ID = ${the_same_id } ` ;
1242+ await client_2 .queryArray ` UPDATE IMPORTANT_TABLE SET PASSWORD = 'something_else' WHERE ID = ${the_same_id } ` ;
12461243
12471244 const { rows : query_2 } = await transaction .queryObject <{
12481245 password: string ;
@@ -1280,14 +1277,12 @@ following levels of transaction isolation:
12801277 }>` SELECT PASSWORD FROM IMPORTANT_TABLE WHERE ID = ${my_id } ` ;
12811278
12821279 // Concurrent operation executed by a different user in a different part of the code
1283- await client_2
1284- .queryArray ` UPDATE IMPORTANT_TABLE SET PASSWORD = 'something_else' WHERE ID = ${the_same_id } ` ;
1280+ await client_2 .queryArray ` UPDATE IMPORTANT_TABLE SET PASSWORD = 'something_else' WHERE ID = ${the_same_id } ` ;
12851281
12861282 // This statement will throw
12871283 // Target was modified outside of the transaction
12881284 // User may not be aware of the changes
1289- await transaction
1290- .queryArray ` UPDATE IMPORTANT_TABLE SET PASSWORD = 'shiny_new_password' WHERE ID = ${the_same_id } ` ;
1285+ await transaction .queryArray ` UPDATE IMPORTANT_TABLE SET PASSWORD = 'shiny_new_password' WHERE ID = ${the_same_id } ` ;
12911286
12921287 // Transaction is aborted, no need to end it
12931288
@@ -1424,7 +1419,7 @@ explained above in the `Savepoint` documentation.
14241419
14251420``` ts
14261421const transaction = client .createTransaction (
1427- " partially_rolled_back_transaction" ,
1422+ " partially_rolled_back_transaction"
14281423);
14291424await transaction .savepoint (" undo" );
14301425await transaction .queryArray ` TRUNCATE TABLE DONT_DELETE_ME ` ; // Oops, wrong table
0 commit comments