UNPKG

@datazod/zod-sql

Version:

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

26 lines 1.7 kB
import { z, ZodObject, ZodRawShape } from 'zod'; import { TableOptions, TableWithMigrationOptions } from '../../types'; /** * Creates a SQL DDL statement from a Zod schema and returns the CREATE TABLE and INDEX statements separately */ export declare function createTable<T extends ZodRawShape>(tableName: string, schema: ZodObject<T>, options?: TableOptions): { table: string; indexes: string[]; schema: z.ZodObject<T, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any>[k]; } : never, z.baseObjectInputType<T> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<T>[k_1]; } : never>; structure: import("../..").TableStructure; schemaJson: Record<string, any>; }; /** * Creates a SQL DDL statement with automatic migration support * Optionally runs migrations if client is provided */ export declare function createTableWithMigration<T extends ZodRawShape>(tableName: string, schema: ZodObject<T>, options?: TableWithMigrationOptions, client?: { execute(sql: string): Promise<any>; }): Promise<{ table: string; indexes: string[]; schema: z.ZodObject<T, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any>[k]; } : never, z.baseObjectInputType<T> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<T>[k_1]; } : never>; structure: import("../..").TableStructure; schemaJson: Record<string, any>; }>; //# sourceMappingURL=index.d.ts.map