diff --git a/examples/scripts/postgres.ts b/examples/scripts/postgres.ts index 2069ae68d..068a056cf 100644 --- a/examples/scripts/postgres.ts +++ b/examples/scripts/postgres.ts @@ -3,30 +3,29 @@ * @difficulty intermediate * @tags cli, deploy * @run --allow-net --allow-env - * @resource {https://deno-postgres.com/} Deno Postgres docs - * @resource {https://deno.land/x/postgres} Deno Postgres on deno.land/x * @group Databases * - * Using the Deno Postgres client, you can connect to a Postgres database + * Using the npm Postgres client, you can connect to a Postgres database * running anywhere. */ -// Import the Client constructor from deno.land/x -import { Client } from "https://deno.land/x/postgres@v0.17.0/mod.ts"; +// Import the Postgres package from +import postgres from "npm:postgres"; // Initialize the client with connection information for your database, and // create a connection. -const client = new Client({ +const sql = postgres({ user: "user", database: "test", hostname: "localhost", port: 5432, }); -await client.connect(); // Execute a SQL query -const result = await client.queryArray("SELECT ID, NAME FROM PEOPLE"); -console.log(result.rows); // [[1, 'Carlos'], [2, 'John'], ...] +const result = await sql` + SELECT ID, NAME FROM PEOPLE +`; +console.log(result); // Close the connection to the database -await client.end(); +await sql.end();