Documentation
supastarter for TanStack Startsupastarter for TanStack StartDatabase

Overview

Learn how to use the database in supastarter.

supastarter for TanStack Start includes a pre-configured database layer powered by Drizzle. PostgreSQL is the default database, but you can also use MySQL or SQLite/libSQL. supastarter works with PostgreSQL-compatible providers like Neon, Supabase, and Railway, plus MySQL providers like PlanetScale and libSQL providers like Turso.

You can find the schema and configuration in the packages/database/drizzle directory.

Database provider guides

Follow a provider-specific guide for detailed setup instructions:

Configure Drizzle

The default PostgreSQL setup works out of the box. If you change providers, make sure the /packages/database/index.ts file exports Drizzle:

packages/database/index.ts
export * from "./drizzle";

The database package scripts should use the Drizzle commands:

package.json
"scripts": {
  "clean": "git clean -xdf .cache .turbo dist node_modules",
  "generate": "echo \"drizzle: no codegen required\"",
  "push": "dotenv -c -e ../../.env -- drizzle-kit push --config=drizzle/drizzle.config.ts",
  "migrate": "dotenv -c -e ../../.env -- drizzle-kit migrate --config=drizzle/drizzle.config.ts",
  "studio": "dotenv -c -e ../../.env -- drizzle-kit studio --config=drizzle/drizzle.config.ts",
  "type-check": "tsc --noEmit"
}

Next make sure to use the drizzle adapter in the /packages/auth/auth.ts file:

packages/auth/auth.ts
export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg", // or "sqlite" or "mysql"
  }),
});

If you are using a different database than PostgreSQL, you will need to export the schema for either mysql or sqlite from the /packages/database/drizzle/schema/index.ts file.

packages/database/drizzle/schema/index.ts
export * from "./postgres";
// or export * from "./mysql";
// or export * from "./sqlite";

Lastly, you will need to set up the correct database client in the client.ts file. Follow the instructions in the Drizzle documentation for the database provider you are using. For PostgreSQL you can use the following example:

packages/database/drizzle/client.ts
import { drizzle } from "drizzle-orm/node-postgres";
import * as schema from "./schema/postgres";

const databaseUrl = process.env.DATABASE_URL as string;

if (!databaseUrl) {
  throw new Error("DATABASE_URL is not set");
}

export const db = drizzle(databaseUrl, {
  schema,
});

Frequently asked questions

Which database should I use with supastarter?

PostgreSQL is the recommended and default database for supastarter. It works out of the box with Drizzle and is supported by all major database providers like Neon, Supabase, and Railway. If you need MySQL or SQLite/libSQL, supastarter supports those through Drizzle as well.

Can I use MySQL or SQLite instead of PostgreSQL?

Yes. supastarter supports MySQL and SQLite/libSQL in addition to PostgreSQL. You will need to update the Drizzle schema export, database client, and auth adapter provider.

Which database provider should I choose?

You are free to choose whatever database provider you want as long as it is compatible with Drizzle. The provider guides in this documentation cover some popular options, but they are not the only choices. That said, here are some recommendations: Neon is great for serverless deployments with connection pooling and branching. Supabase offers a full Postgres platform with storage and real-time features. Railway is simple and affordable for getting started. PlanetScale is ideal if you prefer MySQL with branching. See the database provider guides for setup instructions for each provider.