Skip to content

aerostack generate types

Introspect your connected databases and generate TypeScript interfaces + a type-safe database client.

Terminal window
aerostack generate types [flags]
FlagDefaultDescription
-o, --outputshared/types.tsOutput file path
Terminal window
# Generate types to default location
aerostack generate types
# Custom output path
aerostack generate types --output src/db/types.ts

Given a posts table:

CREATE TABLE posts (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
title TEXT NOT NULL,
published INTEGER DEFAULT 0,
created_at INTEGER NOT NULL
);

The command generates:

// shared/types.ts (auto-generated — do not edit)
export interface Post {
id: string
user_id: string
title: string
published: number
created_at: number
}
export interface DB {
posts: Post
// ... other tables
}
import { DB } from '@shared/types'
const { results } = await sdk.db.query<DB['posts']>(
'SELECT * FROM posts WHERE published = 1'
)
// results is typed as Post[]
  • After creating or modifying a migration
  • After running aerostack db pull
  • As part of your CI pipeline before building