BataDB & Neon

Turbine is the TypeScript ORM layer that ships with BataDB. This page explains the relationship and how to use Turbine with Neon Postgres.


What Is BataDB?

BataDB is a Postgres platform built on Neon's open-source storage engine. It provides:

  • Neon-powered Postgres -- serverless, auto-scaling, branching
  • Turbine ORM -- the TypeScript SDK documented on this site
  • Connection pooling -- built-in proxy with pre-warmed connections

Turbine Works with Any Postgres

Turbine is not locked to BataDB. It works with any Postgres database:

  • Local Postgres (Docker, Homebrew, etc.)
  • Neon
  • Supabase
  • AWS RDS / Aurora
  • Google Cloud SQL
  • Any Postgres >= 14
TypeScript
// Any Postgres connection string works
const db = turbine({
  connectionString: 'postgres://user:pass@any-postgres-host:5432/mydb',
});

Using Turbine with Neon

Neon is the recommended Postgres provider for Turbine because:

  1. Serverless architecture aligns with Turbine's design
  2. Branching makes development workflows fast
  3. Auto-scaling handles production traffic spikes
  4. Low latency on Vercel (same infrastructure)

Setup

Terminal
# 1. Create a Neon database at https://neon.tech
# 2. Copy your connection string

# 3. Initialize Turbine
npx turbine init --url "postgres://user:pass@ep-cool-name.us-east-2.aws.neon.tech/neondb?sslmode=require"

# 4. Generate types
npx turbine generate

Connection String

Neon connection strings look like:

postgres://user:pass@ep-cool-name.us-east-2.aws.neon.tech/neondb?sslmode=require

Set it as DATABASE_URL in your .env:

Terminal
DATABASE_URL="postgres://user:pass@ep-cool-name.us-east-2.aws.neon.tech/neondb?sslmode=require"

Pooled vs Direct Connections

Neon provides two connection modes:

  • Pooled (-pooler in hostname): uses PgBouncer, supports more concurrent connections, recommended for serverless
  • Direct: direct TCP connection, needed for migrations
TypeScript
// For queries (pooled)
const db = turbine({
  connectionString: process.env.DATABASE_URL, // pooled endpoint
});

// For migrations, use direct connection
// npx turbine migrate up --url $DIRECT_DATABASE_URL

Deployment on Vercel

Turbine + Neon + Vercel is the recommended stack for production:

TypeScript
// lib/db.ts
import { turbine } from '@/generated/turbine';

export const db = turbine({
  connectionString: process.env.DATABASE_URL,
  poolSize: 5, // Vercel serverless: keep pool small
});

Server Components

TypeScript
// app/users/page.tsx
import { db } from '@/lib/db';

export default async function UsersPage() {
  const users = await db.users.findMany({
    orderBy: { createdAt: 'desc' },
    limit: 20,
    with: { posts: { limit: 3 } },
  });

  return (
    <div>
      {users.map(user => (
        <div key={user.id}>
          <h2>{user.name}</h2>
          <p>{user.posts.length} posts</p>
        </div>
      ))}
    </div>
  );
}

Server Actions

TypeScript
// app/actions.ts
'use server';

import { db } from '@/lib/db';
import { revalidatePath } from 'next/cache';

export async function createPost(formData: FormData) {
  const post = await db.posts.create({
    data: {
      title: formData.get('title') as string,
      content: formData.get('content') as string,
      userId: 1, // from auth
      orgId: 1,
    },
  });

  revalidatePath('/posts');
  return post;
}