mirror of
https://github.com/supabase/supabase.git
synced 2026-09-07 02:20:52 +08:00
* recreated connecting-to-postgres * adding GUI quickstart section with DBeaver * moved psql and pgadmin docs to GUI quickstart * added Prisma installation docs. Moved postgres.js and Drizzle into own section * added connection management docs * moved supavisor troubleshooting guide into troubleshooting section. Probably should not merge without adding more guides * updated IPv4 Add ons docs * removed typo * Update apps/docs/content/guides/platform/ipv4-address.mdx Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * Update apps/docs/content/guides/platform/ipv4-address.mdx Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * Update apps/docs/content/guides/database/supavisor.mdx Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * Update apps/docs/content/guides/database/prisma.mdx Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * Update apps/docs/content/guides/database/connection-management.mdx Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * Update apps/docs/content/guides/database/connection-management.mdx Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * Update apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * removed repetition in connection-management | added photos * Update apps/docs/content/guides/database/connecting-to-postgres.mdx Co-authored-by: Stas <sts@abc3.dev> * Update apps/docs/content/guides/platform/ipv4-address.mdx Co-authored-by: Stas <sts@abc3.dev> * Update apps/docs/content/guides/database/connection-management.mdx Co-authored-by: Stas <sts@abc3.dev> * Update apps/docs/content/guides/database/connecting-to-postgres.mdx Co-authored-by: Stas <sts@abc3.dev> * Update apps/docs/content/guides/platform/ipv4-address.mdx Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> * Update apps/docs/content/guides/database/connecting-to-postgres.mdx Co-authored-by: Stas <sts@abc3.dev> * updated proxy suggestions * added redirects * added images to connection-management guide * added unique ids to titles in prisma-troubleshooting section * added images to connection guide * added new images to prisma guide * reformatted admonition --------- Co-authored-by: Brian Brennglass <brian@Brians-MacBook-Pro.local> Co-authored-by: Charis <26616127+charislam@users.noreply.github.com> Co-authored-by: Stas <sts@abc3.dev>
88 lines
2.0 KiB
Plaintext
88 lines
2.0 KiB
Plaintext
---
|
|
id: 'postgres-js'
|
|
title: 'Postgres.js'
|
|
description: 'Postgres.js Quickstart'
|
|
breadcrumb: 'ORM Quickstarts'
|
|
hideToc: true
|
|
---
|
|
|
|
### Connecting with Postgres.js
|
|
|
|
[Postgres.js](https://github.com/porsager/postgres) is a full-featured Postgres client for Node.js and Deno.
|
|
|
|
<StepHikeCompact>
|
|
|
|
<StepHikeCompact.Step step={1}>
|
|
|
|
<StepHikeCompact.Details title="Install">
|
|
|
|
Install Postgres.js and related dependencies.
|
|
|
|
</StepHikeCompact.Details>
|
|
|
|
<StepHikeCompact.Code>
|
|
|
|
```shell
|
|
npm i postgres
|
|
```
|
|
|
|
</StepHikeCompact.Code>
|
|
|
|
</StepHikeCompact.Step>
|
|
|
|
<StepHikeCompact.Step step={2}>
|
|
|
|
<StepHikeCompact.Details title="Connect">
|
|
|
|
Create a `db.js` file with the connection details.
|
|
|
|
To get your connection details, go to your [`Database Settings`](https://supabase.com/dashboard/project/_/settings/database). Make sure `Use connection pooling` is enabled. Choose `Transaction Mode` if you're on a platform with transient connections, such as a serverless function, and `Session Mode` if you have a long-lived connection. Copy the URI and save it as the environment variable `DATABASE_URL`.
|
|
|
|
</StepHikeCompact.Details>
|
|
|
|
<StepHikeCompact.Code>
|
|
|
|
```ts
|
|
// db.js
|
|
import postgres from 'postgres'
|
|
|
|
const connectionString = process.env.DATABASE_URL
|
|
const sql = postgres(connectionString)
|
|
|
|
export default sql
|
|
```
|
|
|
|
</StepHikeCompact.Code>
|
|
|
|
</StepHikeCompact.Step>
|
|
|
|
<StepHikeCompact.Step step={3}>
|
|
|
|
<StepHikeCompact.Details title="Execute commands">
|
|
|
|
Use the connection to execute commands.
|
|
|
|
</StepHikeCompact.Details>
|
|
|
|
<StepHikeCompact.Code>
|
|
|
|
```ts
|
|
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
|
|
}
|
|
```
|
|
|
|
</StepHikeCompact.Code>
|
|
|
|
</StepHikeCompact.Step>
|
|
|
|
</StepHikeCompact>
|