Skip to content
BataDB

DocsGet started

Quickstart

Create a Postgres database, run a query, and point your app at it.

You need Node.js 20 or newer for the bata CLI. Everything below can also be done in the console at app.batadata.com.

1. Sign up and add a card

Create an account at app.batadata.com/register. Your account starts with a team on the Free plan.

The Free plan needs a card on file before any database can run. Add one on the console's Billing page. Nothing is charged while you stay inside the free allowance: by default a Free team stops at its allowance instead of billing you. See Pricing and billing.

2. Install the CLI and log in

Terminal
npm install -g @batadata/cli
bata login

bata login prints a code and opens the console. Type the code there and approve it. The CLI saves its own key on this machine, so you log in once.

Terminal
bata whoami

bata whoami shows the team you are working in. Projects are billed to that team.

3. Create a project

Terminal
bata create my-app

This creates a project with one branch, main, and a serverless compute. It waits for the compute to start, then prints the project id and both connection strings.

The new project becomes the default for later commands if you have no default yet. To tie a directory to it, run bata link <project-id> inside it. That writes .batadata/project.json, which holds no secret and is safe to commit.

4. Run a query

Terminal
bata db query "select version()"

Or open an interactive session (needs psql installed):

Terminal
bata db connect

An idle database scales to zero. The first query after a quiet spell wakes it, and bata db query waits for that.

5. Connect your app

Terminal
bata db url --json

You get two connection strings:

  • Pooled goes in your app as DATABASE_URL. Use it for app traffic and serverless functions.
  • Direct goes wherever you need a full session: migrations, pg_dump, LISTEN/NOTIFY. Store it as DIRECT_URL.
TypeScript
import pg from 'pg';

const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
const { rows } = await pool.query('select now()');

Both strings carry the password. Keep them in environment variables, never in code. Connecting covers the difference in detail, plus Prisma and edge runtimes.

6. Give previews their own branch

Terminal
bata db branch create preview
bata db url --branch preview --json

A branch is a copy-on-write copy of its parent's data at the moment you create it, with its own compute and its own connection strings. Point preview deployments at a branch, not at production.

Next steps