---
title: "Pylon Database: typed schema, auto migrations, SQLite or Postgres"
description: "Declare entities in TypeScript. Migrations apply on save. SQLite by default with zero setup; point DATABASE_URL at Postgres and the same schema follows."
url: "https://www.pylonsync.com/product/database"
---

Database

# Typed schema. Migrations on save.

Declare entities in TypeScript with field.string / int / datetime / id and composite indexes. Pylon diffs the schema and applies migrations automatically. SQLite is the one-file default. Point DATABASE\_URL at Postgres and the same schema follows.

[Create your account →](https://cloud.stack0.dev/signup)[Read the docs](https://docs.pylonsync.com)

schema.ts

```


import { entity, field } from "@pylonsync/sdk";

 

const Room = entity("Room", {

  slug: field.string(),

  name: field.string(),

  createdAt: field.datetime(),

});

 

const Message = entity("Message", {

  roomId: field.id("Room").readonly(),

  authorId: field.id("User").readonly(),

  body: field.string(),

  createdAt: field.datetime().readonly(),

});

```

- One fully typed schema file gives your editor every field
- Migrations apply on save in dev; no migration files to hand-author
- SQLite is the default: a single file, nothing to provision
- Set DATABASE\_URL=postgres://… and the same schema targets Postgres

## How it works.

01Field types that mean something02SQLite to Postgres without a rewrite03Migrations you don't babysit

schema.ts

const Order = entity("Order", {

 customer: field.string(),

 total: field.float(),

 paid: field.boolean().default(false),

});

migration applied · 3 columns

field.id("Room") is a typed foreign key, field.richtext() carries formatting, field.datetime() is timezone-correct, field.encrypted() is sealed at rest. Add .readonly() to block HTTP PATCH from rewriting identity fields, .index() for composite indexes. The types flow all the way to db.useQuery on the client.

## What you’d otherwise wire up.

Each line is a piece teams normally assemble for this one capability. On Pylon it is part of the runtime.

- A migration tool and the version table it owns
- An ORM layer plus whatever generates its types
- A hand-written REST or GraphQL API over your own tables
- Connection wiring between the API service and the database

## Apps built with it.

Scaffold any of these with `npm create @pylonsync/pylon`.

[All examples →](/developers/examples)

Barebones

One entity, one function, one page. Start from a clean slate.

SchemaOne functionSSR page

template: barebones

Keep exploring

[Sync engine

Live queries over WebSocket.](/product/sync)

[Auth & policies

Auth and access rules, built in.](/product/auth)

[Search

Full-text search, in your database.](/product/search)

## Build it on Pylon.

One framework for your schema, sync, auth, functions, realtime, and SSR. Free to start.

[Create your account →](https://cloud.stack0.dev/signup)[Read the docs](https://docs.pylonsync.com)
