Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.case.dev/llms.txt

Use this file to discover all available pages before exploring further.

Get PostgreSQL connection strings for your database projects. Supports direct connections, connection pooling, and branch-specific connections.

Get connection string

curl https://api.case.dev/database/v1/projects/proj_abc123/connection \
  -H "Authorization: Bearer $CASEDEV_API_KEY"

Parameters

ParameterTypeRequiredDescription
branchstringNoBranch name (defaults to main)
pooledbooleanNoUse pooled connection via PgBouncer

Response

FieldTypeDescription
connectionUristringPostgreSQL connection string (includes credentials)
branchstringBranch name for this connection
pooledbooleanWhether this is a pooled connection

Direct vs pooled connections

Direct connections

Best for:
  • Long-running processes
  • Migration scripts
  • Administrative tasks
  • Applications with few connections
curl "https://api.case.dev/database/v1/projects/$PROJECT_ID/connection" \
  -H "Authorization: Bearer $CASEDEV_API_KEY"

Pooled connections (PgBouncer)

Best for:
  • Serverless functions
  • High-concurrency applications
  • Short-lived connections
curl "https://api.case.dev/database/v1/projects/$PROJECT_ID/connection?pooled=true" \
  -H "Authorization: Bearer $CASEDEV_API_KEY"
Pooled connections go through PgBouncer, which maintains a pool of database connections. This is essential for serverless environments where you might have many short-lived function invocations.

Branch-specific connections

Get a connection string for a specific branch:
# Get staging branch connection
curl "https://api.case.dev/database/v1/projects/$PROJECT_ID/connection?branch=staging" \
  -H "Authorization: Bearer $CASEDEV_API_KEY"

# Get feature branch connection (pooled)
curl "https://api.case.dev/database/v1/projects/$PROJECT_ID/connection?branch=feature-auth&pooled=true" \
  -H "Authorization: Bearer $CASEDEV_API_KEY"

Integration examples

Drizzle ORM

Typescript
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';

const conn = await client.database.v1.projects.getConnection(projectId);
const sql = postgres(conn.connectionUri);
const db = drizzle(sql);

// Query
const users = await db.select().from(usersTable);

Prisma

Typescript
// Get connection string
const conn = await client.database.v1.projects.getConnection(projectId, {
  pooled: true  // Recommended for Prisma
});

// Set in .env or environment
process.env.DATABASE_URL = conn.connectionUri;

// prisma/schema.prisma
// datasource db {
//   provider = "postgresql"
//   url      = env("DATABASE_URL")
// }

Raw pg (node-postgres)

Typescript
import { Pool } from 'pg';

const conn = await client.database.v1.projects.getConnection(projectId, {
  pooled: true
});

const pool = new Pool({
  connectionString: conn.connectionUri
});

const result = await pool.query('SELECT * FROM users WHERE id = $1', [userId]);

Python psycopg2

Python
import psycopg2

conn = client.database.v1.projects.get_connection(project_id)

db = psycopg2.connect(conn.connection_uri)
cursor = db.cursor()
cursor.execute("SELECT * FROM users WHERE id = %s", (user_id,))

Python SQLAlchemy

Python
from sqlalchemy import create_engine

conn = client.database.v1.projects.get_connection(project_id, pooled=True)

engine = create_engine(conn.connection_uri)
with engine.connect() as connection:
    result = connection.execute("SELECT * FROM users")

Security

Connection strings include database credentials. Never expose them in client-side code, logs, or version control.
Best practices:
  • Store connection strings in environment variables
  • Use secret management services (AWS Secrets Manager, Vault)
  • Rotate credentials periodically
  • Use pooled connections for serverless to limit open connections
Typescript
// Good: Environment variable
const databaseUrl = process.env.DATABASE_URL;

// Bad: Hardcoded
const databaseUrl = "postgresql://user:password@host/db"; // Never do this

Connection string format

postgresql://[user]:[password]@[host]/[database]?sslmode=require
ComponentDescription
userDatabase username
passwordDatabase password
hostNeon endpoint hostname
databaseDatabase name (default: neondb)
sslmodeSSL mode (always require)
Example:
postgresql://neondb_owner:abc123xyz@ep-quiet-meadow-123456.us-east-1.aws.neon.tech/neondb?sslmode=require