SQL CREATE TABLE DDL to Zod Schema Converter
Translate SQL table schemas, data types, constraints, and nullable columns into strongly-typed Zod object schemas.
import { z } from 'zod';
// ============================================================================
// Enums
// ============================================================================
userRoleSchema = z.enum(['SUPERADMIN', 'ORG_ADMIN', 'MEMBER', 'BILLING', 'GUEST']);
UserRole = z.infer<typeof userRoleSchema>;
subscriptionStatusSchema = z.enum(['TRIALING', 'ACTIVE', 'PAST_DUE', 'CANCELED']);
SubscriptionStatus = z.infer<typeof subscriptionStatusSchema>;
// ============================================================================
// Table: organizations
// ============================================================================
organizationsSchema = z.object({
id: z.string().uuid(),
slug: z.string().max(64),
name: z.string().max(255),
billingEmail: z.string().email().max(255),
status: subscriptionStatusSchema,
settings: z.record(z.string(), z.unknown()).nullable(),
isActive: z.boolean(),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
});
Organization = z.infer<typeof organizationsSchema>;
// ============================================================================
// Table: users
// ============================================================================
usersSchema = z.object({
id: z.string().uuid(),
organizationId: z.string().uuid(),
email: z.string().email().max(255),
fullName: z.string().max(120).nullable(),
avatarUrl: z.string().url().max(500).nullable(),
role: userRoleSchema,
phoneNumber: z.string().max(32).nullable(),
isVerified: z.boolean(),
lastLoginAt: z.coerce.date().nullable(),
createdAt: z.coerce.date(),
});
User = z.infer<typeof usersSchema>;
// ============================================================================
// Table: api_keys
// ============================================================================
apiKeysSchema = z.object({
id: z.coerce.number().int().positive(),
organizationId: z.string().uuid(),
userId: z.string().uuid().nullable(),
keyPrefix: z.string().max(12),
hashedSecret: z.string().max(128),
scopes: z.record(z.string(), z.unknown()),
expiresAt: z.coerce.date().nullable(),
revokedAt: z.coerce.date().nullable(),
createdAt: z.coerce.date(),
});
ApiKey = z.infer<typeof apiKeysSchema>;
// ============================================================================
// Table: audit_logs
// ============================================================================
auditLogsSchema = z.object({
id: z.coerce.number().int().positive(),
organizationId: z.string().uuid(),
actorId: z.string().uuid().nullable(),
eventName: z.string().max(100),
ipAddress: z.string().ip().nullable(),
userAgent: z.string().max(500).nullable(),
payload: z.record(z.string(), z.unknown()).nullable(),
createdAt: z.coerce.date(),
});
AuditLog = z.infer<typeof auditLogsSchema>;
Zero-Knowledge Local Execution
All data processing, parsing, and compilation execute strictly inside your local browser memory. Zero external server uploads.
Sub-Millisecond AST Engine
All data payloads remain strictly local with zero external server communication.
Production Ready Export
Clean, optimized output formats ready for immediate deployment.