deno.com

Connect to Postgres

在 Github 上编辑

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

Import the Postgres package from
import postgres from "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();

使用 Deno CLI 在本地运行 此示例

deno run --allow-net --allow-env https://docs.denohub.com/examples/scripts/postgres.ts

你找到需要的内容了吗?

隐私政策