Home / Function/ createSchemaFactory() — drizzle-orm Function Reference

createSchemaFactory() — drizzle-orm Function Reference

Architecture documentation for the createSchemaFactory() function in schema.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  d2723733_6712_bbee_d681_bb39a01d2185["createSchemaFactory()"]
  91122f81_e9f3_fa04_26c5_a8235e0646d0["schema.ts"]
  d2723733_6712_bbee_d681_bb39a01d2185 -->|defined in| 91122f81_e9f3_fa04_26c5_a8235e0646d0
  30f11dbc_6f36_6bc4_19b5_3bbdaab388a4["handleEnum()"]
  d2723733_6712_bbee_d681_bb39a01d2185 -->|calls| 30f11dbc_6f36_6bc4_19b5_3bbdaab388a4
  3c88ca67_abce_f09c_3f03_3fda2893c4c6["getColumns()"]
  d2723733_6712_bbee_d681_bb39a01d2185 -->|calls| 3c88ca67_abce_f09c_3f03_3fda2893c4c6
  af586672_33cc_3a35_8f1d_b940b9fbdc63["handleColumns()"]
  d2723733_6712_bbee_d681_bb39a01d2185 -->|calls| af586672_33cc_3a35_8f1d_b940b9fbdc63
  style d2723733_6712_bbee_d681_bb39a01d2185 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-zod/src/schema.ts lines 121–152

export function createSchemaFactory<
	TCoerce extends Partial<Record<'bigint' | 'boolean' | 'date' | 'number' | 'string', true>> | true | undefined,
>(options?: CreateSchemaFactoryOptions<TCoerce>) {
	const createSelectSchema: CreateSelectSchema<TCoerce> = (
		entity: Table | View | PgEnum<[string, ...string[]]>,
		refine?: Record<string, any>,
	) => {
		if (isPgEnum(entity)) {
			return handleEnum(entity, options);
		}
		const columns = getColumns(entity);
		return handleColumns(columns, refine ?? {}, selectConditions, options) as any;
	};

	const createInsertSchema: CreateInsertSchema<TCoerce> = (
		entity: Table,
		refine?: Record<string, any>,
	) => {
		const columns = getColumns(entity);
		return handleColumns(columns, refine ?? {}, insertConditions, options) as any;
	};

	const createUpdateSchema: CreateUpdateSchema<TCoerce> = (
		entity: Table,
		refine?: Record<string, any>,
	) => {
		const columns = getColumns(entity);
		return handleColumns(columns, refine ?? {}, updateConditions, options) as any;
	};

	return { createSelectSchema, createInsertSchema, createUpdateSchema };
}

Subdomains

Frequently Asked Questions

What does createSchemaFactory() do?
createSchemaFactory() is a function in the drizzle-orm codebase, defined in drizzle-zod/src/schema.ts.
Where is createSchemaFactory() defined?
createSchemaFactory() is defined in drizzle-zod/src/schema.ts at line 121.
What does createSchemaFactory() call?
createSchemaFactory() calls 3 function(s): getColumns, handleColumns, handleEnum.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free