本页还没有译文
本页 12 段还没译成Español,下面显示的是英文原文。Postgres.js
还没翻译译自英文(supabase.com)本页 12 段都还没译
Connecting with Postgres.js
Postgres.js is a full-featured Postgres client for Node.js and Deno.
-
Install
Install Postgres.js and related dependencies.
npm i postgres -
Connect
Create a
db.jsfile with the connection details.To get your connection details, go to the Connect panel. Choose Transaction pooler if you're on a platform with transient connections, such as a serverless function, and Session pooler if you have a long-lived connection. Copy the URI and save it as the environment variable
DATABASE_URL.Caution
postgres.jspipelines queries by default. Combined with the shared pooler transaction mode, this can hang queries or return mismatched rows.postgres.jshas no working option to turn pipelining off directly:max_pipeline: 0breakssql.begin()transactions instead, a known upstream bug.For more about pipelining with
postgres.js, contact support.// db.js import postgres from 'postgres' const connectionString = process.env.DATABASE_URL const sql = postgres(connectionString, { prepare: false }) export default sql -
Execute commands
Use the connection to execute commands.
import sql from './db.js' async function getUsersOver(age) { const users = await sql` select name, age from users where age > ${ age } ` // users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...] return users }