On this page

Typed clients

TypeScript, Dart, Swift and Kotlin types generated from your schema, kept up to date on every schema change: at a stable link, as a webhook and as a GitHub pull request.

StitchDB generates types for your tables, views and enums in four languages, in the shape the SDKs use. When a column is renamed or a table dropped, your app stops compiling instead of failing in production. You can get the types once, or have them regenerated on every schema change.

LanguageFileWhat you get
TypeScriptdatabase.types.tsA Database type for createClient<Database>() in stitchdb-js: Row, Insert and Update per table, views, functions, enums, relationships
Dart (Flutter)database_types.dartA class per table and view with fromJson / toJson, a …Insert class per table, enums. No packages needed
SwiftDatabaseTypes.swiftCodable, Hashable, Sendable structs inside enum Database, an insert struct per table, enums, and Database.JSON for json columns
KotlinDatabaseTypes.kt@Serializable data classes for kotlinx.serialization, an insert class per table, enums; json columns are JsonElement

Column names become the language's usual style (created_at → createdAt) and map back to the real names when encoding. Timestamps, dates, UUIDs and other text-like types are strings, exactly as the API returns them. In the insert types, columns with a default, an identity or that allow null are optional and left out when not set, so the database default applies; generated columns are not in them.

#Get the types once

In Studio open Database › Typed clients, pick a language and download the file. Or use the CLI:

Terminal
stitchdb gen types typescript --linked -o src/database.types.ts
stitchdb gen types dart --linked -o lib/database_types.dart
stitchdb gen types swift --linked -o Sources/App/DatabaseTypes.swift
stitchdb gen types kotlin --linked --package com.example.db -o app/src/main/kotlin/DatabaseTypes.kt

Add -s public,api for more schemas and --local for the local stack. The management API has the same at GET /v1/projects/<ref>/types/<language>.

#Keep a file up to date while you work

Terminal
stitchdb types --watch -o src/database.types.ts
stitchdb types --lang swift --watch -o Sources/App/DatabaseTypes.swift

The CLI checks the schema (every second for --local, every 5 seconds otherwise; change it with --interval) and rewrites the file only when the types change, so your editor and dev server pick them up at once.

#Regenerate on every schema change

In Database › Typed clients turn on Keep types up to date (project owners and admins). StitchDB checks the schema about every two minutes; when the types change it publishes a new version, numbered from 1:

WhereHow
Stable linksOne secret link per language, like https://stitchdb.com/platform/types/<ref>/<token>/database.types.ts, plus version.json. Responses carry an ETag and a StitchDB-Types-Version header, so curl -z or a build step downloads only a changed file. Make new links replaces the token; the old links stop working.
WebhookA types.updated event to every webhook that chose it, with record = { version, sha, languages, urls }. Use it to start a CI build.
GitHub pull requestWith a linked repository, each version is committed to the branch stitchdb/types (reset onto your base branch every time) and proposed in one pull request that is kept up to date.
Terminal
# in CI: fetch the latest types before building
curl -fsS -z src/database.types.ts -o src/database.types.ts "$STITCHDB_TYPES_URL"

Changes that don't change the types, like a new index or new rows, publish nothing. A paused project is not checked.

Create a fine-grained personal access token for just that repository with Contents and Pull requests set to Read and write. In Typed clients › Pull requests on GitHub enter the repository (owner/name), the base branch (empty for the default branch), the folder and which files to commit, and paste the token. The token is stored encrypted and never shown again; Unlink deletes it. If GitHub refuses a request (an expired token, a protected branch), the error is shown there and the next version tries again.