SQL DDL zu Kysely TypeScript Database Interface Generator
Autoritative Referenz zur Konvertierung von SQL-DDL-Schemas in typsichere Kysely-TypeScript-Definitionen für PostgreSQL-, MySQL- und SQLite-Dialekte.
/**
* Generated by ToolsAA SQL to Kysely TypeGen
* Target Dialect: POSTGRES
* Generated Tables: 4
*/
import type { ColumnType, Generated, Insertable, Selectable, Updateable } from 'kysely';
// ==========================================
// Enums & Custom Value Types
// ==========================================
export type UserRole = 'OWNER' | 'ADMIN' | 'MEMBER' | 'BILLING_CONTACT';
export type SubscriptionStatus = 'TRIALING' | 'ACTIVE' | 'PAST_DUE' | 'CANCELED' | 'INCOMPLETE';
export type InvoiceStatus = 'DRAFT' | 'OPEN' | 'PAID' | 'UNCOLLECTIBLE' | 'VOID';
// ==========================================
// Table Interfaces
// ==========================================
export interface OrganizationsTable {
id: Generated<string>; // PRIMARY KEY | DEFAULT: gen_random_uuid()
slug: string;
name: string;
settings: ColumnType<Record<string, unknown> | null, string | Record<string, unknown> | null, string | Record<string, unknown> | null | undefined>;
is_active: Generated<boolean>; // DEFAULT: true
created_at: Generated<Date>; // DEFAULT: CURRENT_TIMESTAMP
updated_at: Generated<Date>; // DEFAULT: CURRENT_TIMESTAMP
}
export interface UsersTable {
id: Generated<string>; // PRIMARY KEY | DEFAULT: gen_random_uuid()
organization_id: string; // FK -> organizations.id
email: string;
full_name: string | null;
role: Generated<UserRole>; // DEFAULT: MEMBER
avatar_url: string | null;
last_login_at: Date | null;
created_at: Generated<Date>; // DEFAULT: CURRENT_TIMESTAMP
}
export interface SubscriptionsTable {
id: Generated<string>; // PRIMARY KEY | DEFAULT: gen_random_uuid()
organization_id: string; // FK -> organizations.id
stripe_customer_id: string;
stripe_subscription_id: string | null;
plan_tier: Generated<string>; // DEFAULT: starter
seat_count: Generated<number>; // DEFAULT: 5
status: Generated<SubscriptionStatus>; // DEFAULT: TRIALING
current_period_start: Date;
current_period_end: Date;
cancel_at_period_end: Generated<boolean>; // DEFAULT: false
created_at: Generated<Date>; // DEFAULT: CURRENT_TIMESTAMP
}
export interface InvoicesTable {
id: Generated<string>; // PRIMARY KEY | DEFAULT: gen_random_uuid()
organization_id: string; // FK -> organizations.id
subscription_id: string | null; // FK -> subscriptions.id
invoice_number: string;
subtotal_cents: Generated<number>; // DEFAULT: 0
tax_cents: Generated<number>; // DEFAULT: 0
total_cents: Generated<number>; // DEFAULT: 0
currency: Generated<string>; // DEFAULT: USD
status: Generated<InvoiceStatus>; // DEFAULT: OPEN
paid_at: Date | null;
line_items: ColumnType<Record<string, unknown>, string | Record<string, unknown>, string | Record<string, unknown> | undefined>;
created_at: Generated<Date>; // DEFAULT: CURRENT_TIMESTAMP
}
// ==========================================
// Master Database Interface
// ==========================================
export interface Database {
organizations: OrganizationsTable;
users: UsersTable;
subscriptions: SubscriptionsTable;
invoices: InvoicesTable;
}
// ==========================================
// Convenience Entity Models (Select / Insert / Update)
// ==========================================
export type Organization = Selectable<OrganizationsTable>;
export type NewOrganization = Insertable<OrganizationsTable>;
export type OrganizationUpdate = Updateable<OrganizationsTable>;
export type User = Selectable<UsersTable>;
export type NewUser = Insertable<UsersTable>;
export type UserUpdate = Updateable<UsersTable>;
export type Subscription = Selectable<SubscriptionsTable>;
export type NewSubscription = Insertable<SubscriptionsTable>;
export type SubscriptionUpdate = Updateable<SubscriptionsTable>;
export type Invoic = Selectable<InvoicesTable>;
export type NewInvoic = Insertable<InvoicesTable>;
export type InvoicUpdate = Updateable<InvoicesTable>;Vollständige lokale Privatsphäre
Alle SQL-Parser- und TypeScript-Generierungsprozesse laufen zu 100% lokal in Ihrer Browser-Sandbox. Keine Daten verlassen Ihren Rechner.
Präzise Kysely-Typsicherheit
Präzises Mapping von SQL-Typen auf TypeScript, einschließlich Generated<T> für Auto-Inkremente und Defaults sowie ColumnType für asymmetrische Spalten.
Selectable, Insertable & Updateable
Erstellt standardmäßig die zentrale Database-Schnittstelle sowie Selectable<T>, Insertable<T> und Updateable<T> Hilfstypen für Kysely.