Skip to content

Quick Start

Get up and running with Astroladb in three simple steps: initialize, configure, and create your first schema.

Terminal window
mkdir myapp && cd myapp
alab init

This creates the basic project structure with configuration files and sample directories.

After running alab init, you’ll have:

myapp/
├── alab.yaml # Configuration file
├── schemas/ # Your schema definitions
├── migrations/ # Generated SQL migrations
└── types/ # TypeScript definitions for IDE support
File/FolderPurpose
alab.yamlDatabase connection and project settings
schemas/JavaScript files defining your tables
migrations/Auto-generated SQL migration files
types/TypeScript definitions for col and table autocomplete

Edit alab.yaml with your database connection:

database:
dialect: postgres
url: postgres://user:password@localhost:5432/mydb
schemas: ./schemas
migrations: ./migrations
database:
dialect: sqlite
url: ./dev.db
schemas: ./schemas
migrations: ./migrations
SettingDescriptionExample
database.dialectDatabase typepostgres or sqlite
database.urlConnection stringSee examples above
schemasPath to schema definitions./schemas
migrationsPath to migration output./migrations

Use the alab table command to scaffold a new schema file:

Terminal window
alab table auth user

This creates schemas/auth/user.js with a basic template. Edit it to define your columns:

schemas/auth/user.js
export default table({
id: col.id(),
email: col.email().unique(),
username: col.username().unique(),
password: col.password_hash(),
is_active: col.flag(true),
}).timestamps();

Generate a migration from your schema:

Terminal window
alab new create_users

Preview the SQL before applying:

Terminal window
alab migrate --dry

Apply the migration to your database:

Terminal window
alab migrate

You now have a working Astroladb project! Here are some next steps:

Terminal window
alab table blog post
alab table blog comment
alab table blog tag

Creates:

  • schemas/blog/post.js
  • schemas/blog/comment.js
  • schemas/blog/tag.js
Terminal window
alab table auth user
alab table catalog product
alab table orders order

Organizes tables by domain: