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.
What Gets Exported
Section titled “What Gets Exported”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
Export Commands
Section titled “Export Commands”# Export everythingalab export -f all
# Export specific formatalab export -f typescriptalab export -f openapi
# Merge into single files per formatalab export -f all --mergeSupported Formats
Section titled “Supported Formats”| Format | Output | Use Case |
|---|---|---|
typescript | Interfaces, type definitions | Frontend, Node.js backend |
go | Structs with JSON tags | Go APIs and services |
python | Dataclasses with type hints | Python APIs, data science |
rust | Structs with Serde derives | Rust services |
openapi | OpenAPI 3.0 specification | API documentation, codegen |
graphql | GraphQL schema definitions | GraphQL APIs |
Output Directory
Section titled “Output Directory”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.graphqlExport Behavior
Section titled “Export Behavior”What’s Included
Section titled “What’s Included”- All column fields with their types
- Validation constraints (min, max, pattern)
- Format hints (email, uri, etc.)
- Documentation from
.docs()modifiers - Enum values
- Relationship references
What’s Excluded
Section titled “What’s Excluded”- Columns marked with
x-hidden(e.g.,col.password_hash()) - Internal metadata columns
- Migration-specific configurations
Type Mapping
Section titled “Type Mapping”| Schema Type | TypeScript | Go | Python | Rust |
|---|---|---|---|---|
col.id() | string | string | str | String |
col.string() | string | string | str | String |
col.text() | string | string | str | String |
col.integer() | number | int | int | i32 |
col.float() | number | float64 | float | f64 |
col.decimal() | number | float64 | Decimal | f64 |
col.boolean() | boolean | bool | bool | bool |
col.datetime() | Date | time.Time | datetime | DateTime |
col.date() | Date | time.Time | date | NaiveDate |
col.json() | any | interface{} | dict | Value |
col.enum([...]) | union type | string | Literal | enum |
Nullable Fields
Section titled “Nullable Fields”Optional columns (.optional()) are mapped to nullable types:
- TypeScript:
string | null - Go:
*string(pointer) - Python:
str | NoneorOptional[str] - Rust:
Option<String>
Example Export
Section titled “Example Export”Given this schema:
export default table({ id: col.id(), title: col.title(), content: col.body(), published: col.flag(), author: col.belongs_to("auth.user"),}).timestamps();TypeScript Output
Section titled “TypeScript Output”export interface Post { id: string; title: string; content: string; published: boolean; author_id: string; created_at: Date; updated_at: Date;}Go Output
Section titled “Go Output”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"`}Python Output
Section titled “Python Output”from dataclasses import dataclassfrom datetime import datetime
@dataclassclass Post: id: str title: str content: str published: bool author_id: str created_at: datetime updated_at: datetimeWorkflow Integration
Section titled “Workflow Integration”Exports are designed to integrate into your development workflow:
- Define schema in
schemas/ - Run migrations with
alab migrate - Export types with
alab export -f all - Import in code and get full type safety
CI/CD Example
Section titled “CI/CD Example”#!/bin/bash# In your CI pipeline
# Apply migrationsalab migrate
# Export types for all languagesalab export -f all
# Commit generated filesgit add generated/git commit -m "Update generated types"Watch Mode (Future)
Section titled “Watch Mode (Future)”While not currently implemented, future versions may support watch mode:
# Watch for schema changes and auto-export (future feature)alab watchBest Practices
Section titled “Best Practices”- Commit generated files - Treat them as build artifacts for code review
- Use separate branches - Export types in feature branches alongside schema changes
- Version control exports - Track changes to understand API evolution
- Document breaking changes - Use semantic versioning when types change
- Validate before deploy - Run
alab checkto validate schemas before exporting