Skip to content
GitHubXDiscordRSS

Database

The Database resource lets you create and manage Prisma Postgres database resources within an alchemy project. Each database is a fully managed PostgreSQL instance that can be connected to applications.

Create a basic database in a project:

import { Database } from "alchemy/prisma-postgres";
const database = await Database("my-db", {
project: "prj_12345abcde",
});
console.log(`Database ID: ${database.id}`);
console.log(`Database Name: ${database.name}`);
console.log(`Status: ${database.status}`);

Create a database using a Project resource:

import { Project, Database } from "alchemy/prisma-postgres";
const project = await Project("my-app");
const database = await Database("production", {
project: project,
});

Create databases in various regions:

import { Database } from "alchemy/prisma-postgres";
// Asia Pacific
const apDatabase = await Database("ap-db", {
project: project,
region: "ap-northeast-1"
});

By default, databases are not deleted when the Alchemy resource is destroyed. Enable deletion for ephemeral databases:

import { Database } from "alchemy/prisma-postgres";
const testDatabase = await Database("test-db", {
project: "prj_12345abcde",
region: "us-east-1",
delete: true // Will delete the database on destroy
});

Create a database and connection string for your application:

import { Project, Database, Connection } from "alchemy/prisma-postgres";
const project = await Project("my-app");
const database = await Database("production", {
project: project,
region: "us-east-1"
});
const connection = await Connection("app-connection", {
database: database,
});
console.log(`Connection string available at: ${connection.connectionString.unencrypted}`);
  • Project - Create projects to contain databases
  • Connection - Create connection strings for databases
  • Workspace - Learn about Prisma workspaces