UNPKG

@datazod/zod-sql

Version:

Convert Zod schemas to SQL table definitions with support for SQLite, PostgreSQL, and MySQL

46 lines 1.71 kB
import { z } from 'zod'; /** * Flatten an interface by converting nested objects to underscore notation */ export type TableTypes<T, Prefix extends string = ''> = T extends Record<string, any> ? { [K in keyof T as K extends string ? T[K] extends Record<string, any> ? T[K] extends any[] ? `${Prefix}${K}` : never : `${Prefix}${K}` : never]: T[K] extends any[] ? T[K] : T[K] extends Record<string, any> ? never : T[K]; } & { [K in keyof T as K extends string ? T[K] extends Record<string, any> ? T[K] extends any[] ? never : `${Prefix}${K}_${keyof T[K] & string}` : never : never]: K extends string ? T[K] extends Record<string, any> ? T[K] extends any[] ? never : T[K][keyof T[K]] : never : never; } : never; /** * Pre-built schemas for common table fields */ export declare const timeStampsSchema: z.ZodObject<{ created_at: z.ZodString; updated_at: z.ZodString; }, "strip", z.ZodTypeAny, { created_at: string; updated_at: string; }, { created_at: string; updated_at: string; }>; export declare const autoIdSchema: z.ZodObject<{ id: z.ZodString; }, "strip", z.ZodTypeAny, { id: string; }, { id: string; }>; export declare const autoIdSchemaWithTimestamps: z.ZodObject<{ id: z.ZodString; created_at: z.ZodString; updated_at: z.ZodString; }, "strip", z.ZodTypeAny, { created_at: string; updated_at: string; id: string; }, { created_at: string; updated_at: string; id: string; }>; export type TimeStampsSchema = z.infer<typeof timeStampsSchema>; export type AutoIdSchema = z.infer<typeof autoIdSchema>; export type AutoIdSchemaWithTimestamps = z.infer<typeof autoIdSchemaWithTimestamps>; //# sourceMappingURL=schema.d.ts.map