Skip to content

Export Overview

Astroladb exports your schema definitions to multiple languages and API specifications, keeping your types synchronized across your entire stack.

One schema, many outputs. Define your data model once, then export it to whatever languages and frameworks your project uses.

From a single schema definition, Astroladb generates:

  • Language Types: Strongly-typed definitions for TypeScript, Go, Python, and Rust
  • API Specifications: OpenAPI 3.0 and GraphQL schema definitions
  • Validation Rules: Min/max constraints, patterns, and format hints
  • Documentation: Comments and descriptions from .docs() modifiers
Terminal window
# Export everything
alab export -f all
# Export specific format
alab export -f typescript
alab export -f openapi
# Merge into single files per format
alab export -f all --merge
FormatOutputUse Case
typescriptInterfaces, type definitionsFrontend, Node.js backend
goStructs with JSON tagsGo APIs and services
pythonDataclasses with type hintsPython APIs, data science
rustStructs with Serde derivesRust services
openapiOpenAPI 3.0 specificationAPI documentation, codegen
graphqlGraphQL schema definitionsGraphQL APIs

By default, exports are written to ./generated/<format>/:

generated/
├── typescript/
│ ├── auth/
│ │ └── user.ts
│ └── blog/
│ └── post.ts
├── go/
│ ├── auth/
│ │ └── user.go
│ └── blog/
│ └── post.go
├── openapi/
│ └── openapi.yaml
└── graphql/
└── schema.graphql
  • All column fields with their types
  • Validation constraints (min, max, pattern)
  • Format hints (email, uri, etc.)
  • Documentation from .docs() modifiers
  • Enum values
  • Relationship references
  • Columns marked with x-hidden (e.g., col.password_hash())
  • Internal metadata columns
  • Migration-specific configurations
Schema TypeTypeScriptGoPythonRust
col.id()stringstringstrString
col.string()stringstringstrString
col.text()stringstringstrString
col.integer()numberintinti32
col.float()numberfloat64floatf64
col.decimal()numberfloat64Decimalf64
col.boolean()booleanboolboolbool
col.datetime()Datetime.TimedatetimeDateTime
col.date()Datetime.TimedateNaiveDate
col.json()anyinterface{}dictValue
col.enum([...])union typestringLiteralenum

Optional columns (.optional()) are mapped to nullable types:

  • TypeScript: string | null
  • Go: *string (pointer)
  • Python: str | None or Optional[str]
  • Rust: Option<String>

Given this schema:

schemas/blog/post.js
export default table({
id: col.id(),
title: col.title(),
content: col.body(),
published: col.flag(),
author: col.belongs_to("auth.user"),
}).timestamps();
generated/typescript/blog/post.ts
export interface Post {
id: string;
title: string;
content: string;
published: boolean;
author_id: string;
created_at: Date;
updated_at: Date;
}
generated/go/blog/post.go
package blog
import "time"
type Post struct {
ID string `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
Published bool `json:"published"`
AuthorID string `json:"author_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
generated/python/blog/post.py
from dataclasses import dataclass
from datetime import datetime
@dataclass
class Post:
id: str
title: str
content: str
published: bool
author_id: str
created_at: datetime
updated_at: datetime

Exports are designed to integrate into your development workflow:

  1. Define schema in schemas/
  2. Run migrations with alab migrate
  3. Export types with alab export -f all
  4. Import in code and get full type safety
#!/bin/bash
# In your CI pipeline
# Apply migrations
alab migrate
# Export types for all languages
alab export -f all
# Commit generated files
git add generated/
git commit -m "Update generated types"

While not currently implemented, future versions may support watch mode:

Terminal window
# Watch for schema changes and auto-export (future feature)
alab watch
  1. Commit generated files - Treat them as build artifacts for code review
  2. Use separate branches - Export types in feature branches alongside schema changes
  3. Version control exports - Track changes to understand API evolution
  4. Document breaking changes - Use semantic versioning when types change
  5. Validate before deploy - Run alab check to validate schemas before exporting