Skip to content

Commit 7fd2b02

Browse files
Update example to use npm package for postgres (#1379)
1 parent d060f13 commit 7fd2b02

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

examples/scripts/postgres.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,29 @@
33
* @difficulty intermediate
44
* @tags cli, deploy
55
* @run --allow-net --allow-env <url>
6-
* @resource {https://deno-postgres.com/} Deno Postgres docs
7-
* @resource {https://deno.land/x/postgres} Deno Postgres on deno.land/x
86
* @group Databases
97
*
10-
* Using the Deno Postgres client, you can connect to a Postgres database
8+
* Using the npm Postgres client, you can connect to a Postgres database
119
* running anywhere.
1210
*/
1311

14-
// Import the Client constructor from deno.land/x
15-
import { Client } from "https://deno.land/x/postgres@v0.17.0/mod.ts";
12+
// Import the Postgres package from
13+
import postgres from "npm:postgres";
1614

1715
// Initialize the client with connection information for your database, and
1816
// create a connection.
19-
const client = new Client({
17+
const sql = postgres({
2018
user: "user",
2119
database: "test",
2220
hostname: "localhost",
2321
port: 5432,
2422
});
25-
await client.connect();
2623

2724
// Execute a SQL query
28-
const result = await client.queryArray("SELECT ID, NAME FROM PEOPLE");
29-
console.log(result.rows); // [[1, 'Carlos'], [2, 'John'], ...]
25+
const result = await sql`
26+
SELECT ID, NAME FROM PEOPLE
27+
`;
28+
console.log(result);
3029

3130
// Close the connection to the database
32-
await client.end();
31+
await sql.end();

0 commit comments

Comments
 (0)