Planetscale.Postgres reference
PostgresBranch
Section titled “PostgresBranch”Source:
packages/planetscale/src/Postgres/PostgresBranch.ts
A branch of a PlanetScale Postgres database.
PostgresBranch: Looking up an existing Postgres branch
Section titled “PostgresBranch: Looking up an existing Postgres branch”PostgresBranch.lookup references a Postgres branch Alchemy doesn’t manage (created in
the PlanetScale dashboard or by another stack). It is read during
plan/deploy, never created, updated or deleted.
const main = Planetscale.PostgresBranch.lookup({ database: "app", name: "main" });PostgresDatabase
Section titled “PostgresDatabase”Source:
packages/planetscale/src/Postgres/PostgresDatabase.ts
A PlanetScale Postgres database.
PostgresDatabase: Looking up an existing Postgres database
Section titled “PostgresDatabase: Looking up an existing Postgres database”PostgresDatabase.lookup references a Postgres database Alchemy doesn’t manage (created in
the PlanetScale dashboard or by another stack). It is read during
plan/deploy, never created, updated or deleted.
const db = Planetscale.PostgresDatabase.lookup({ name: "app" });const preview = yield* Planetscale.PostgresBranch("Preview", { database: db, isProduction: false,});PostgresDefaultRole
Section titled “PostgresDefaultRole”Source:
packages/planetscale/src/Postgres/PostgresDefaultRole.ts
The default PlanetScale PostgreSQL role for a database branch.
PostgresDefaultRole: Creating a Default Role
Section titled “PostgresDefaultRole: Creating a Default Role”const db = yield* Planetscale.PostgresDatabase("MyDb", { clusterSize: "PS_10",});const defaultRole = yield* Planetscale.PostgresDefaultRole("MainRole", { database: db, forceReset: true,});PostgresRole
Section titled “PostgresRole”Source:
packages/planetscale/src/Postgres/PostgresRole.ts
A PlanetScale role for accessing a PostgreSQL database branch.
For MySQL databases, use MySQLPassword instead.
PostgresRole: Creating a Role
Section titled “PostgresRole: Creating a Role”Postgres admin role
const admin = yield* Planetscale.PostgresRole("Admin", { database: "my-db", inheritedRoles: ["postgres"],});Read-only role
const reader = yield* Planetscale.PostgresRole("Reader", { database: "my-db", inheritedRoles: ["pg_read_all_data", "pg_read_all_settings"],});Role with TTL
const tempReader = yield* Planetscale.PostgresRole("TempReader", { database: "my-db", inheritedRoles: ["pg_read_all_data"], ttl: 3600,});