Générateur d'Interfaces TypeScript Kysely depuis SQL DDL
Manuel technique de référence et générateur de schémas pour convertir des définitions SQL DDL en interfaces TypeScript Kysely robustes pour PostgreSQL, MySQL et SQLite.
/**
* 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>;Confidentialité Locale Zéro-Upload
Toute l'analyse SQL et la génération des interfaces TypeScript s'exécutent à 100% dans le bac à sable de votre navigateur. Vos données ne quittent jamais votre machine.
Précision du Typage Kysely
Mappage rigoureux des types SQL vers TypeScript, encapsulant les auto-incréments et valeurs par défaut dans Generated<T> et les colonnes JSON dans ColumnType.
Selectable, Insertable & Updateable
Génère l'interface principale Database et les types utilitaires Selectable<T>, Insertable<T> et Updateable<T> prêts pour le query builder Kysely.