Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
⌘K
Up or down tonavigateEnter toselectEscape toclose

Connect to Postgres

Using the npm Postgres client, you can connect to a Postgres database running anywhere.

Import the Postgres package from
import postgresfrom"npm:postgres";
Initialize the client with connection information for your database, and create a connection.
const sql=postgres({user:"user",database:"test",hostname:"localhost",port:5432,});
Execute a SQL query
const result=await sql`  SELECT ID, NAME FROM PEOPLE`;console.log(result);
Close the connection to the database
await sql.end();

Runthis example locally using the Deno CLI:

deno run -N -E https://docs.deno.com/examples/scripts/postgres.ts

Did you find what you needed?

What can we do to improve this page?

If provided, you'll be @mentioned in the created GitHub issue

Privacy policy

[8]ページ先頭

©2009-2025 Movatter.jp