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

handleColumns() — drizzle-orm Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  8f6a4e48_fad1_f6d4_41bd_580208780715["handleColumns()"]
  8dacc372_d6d5_e273_f9e6_3a10af9bc4a7["schema.ts"]
  8f6a4e48_fad1_f6d4_41bd_580208780715 -->|defined in| 8dacc372_d6d5_e273_f9e6_3a10af9bc4a7
  e472c7e2_9a22_2d33_4b6b_6183dc44a361["createSelectSchema()"]
  e472c7e2_9a22_2d33_4b6b_6183dc44a361 -->|calls| 8f6a4e48_fad1_f6d4_41bd_580208780715
  fc4b08ff_4c39_7dc9_7a1b_6d0eb729e8a9["createInsertSchema()"]
  fc4b08ff_4c39_7dc9_7a1b_6d0eb729e8a9 -->|calls| 8f6a4e48_fad1_f6d4_41bd_580208780715
  3709c255_eab8_8196_a256_19459b96246e["createUpdateSchema()"]
  3709c255_eab8_8196_a256_19459b96246e -->|calls| 8f6a4e48_fad1_f6d4_41bd_580208780715
  3256d459_405c_31dd_26e8_34b91d485d81["createSchemaFactory()"]
  3256d459_405c_31dd_26e8_34b91d485d81 -->|calls| 8f6a4e48_fad1_f6d4_41bd_580208780715
  a1c23736_0b64_ccf3_cdc8_9fef2996891c["getColumns()"]
  8f6a4e48_fad1_f6d4_41bd_580208780715 -->|calls| a1c23736_0b64_ccf3_cdc8_9fef2996891c
  06e21ad5_4a79_38ca_ddc3_d0ed3cb1ab5c["columnToSchema()"]
  8f6a4e48_fad1_f6d4_41bd_580208780715 -->|calls| 06e21ad5_4a79_38ca_ddc3_d0ed3cb1ab5c
  style 8f6a4e48_fad1_f6d4_41bd_580208780715 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-typebox/src/schema.ts lines 20–63

export function handleColumns(
	columns: Record<string, any>,
	refinements: Record<string, any>,
	conditions: Conditions,
	factory?: CreateSchemaFactoryOptions,
): TSchema {
	const columnSchemas: Record<string, TSchema> = {};

	for (const [key, selected] of Object.entries(columns)) {
		if (!is(selected, Column) && !is(selected, SQL) && !is(selected, SQL.Aliased) && typeof selected === 'object') {
			const columns = isTable(selected) || isView(selected) ? getColumns(selected) : selected;
			columnSchemas[key] = handleColumns(columns, refinements[key] ?? {}, conditions, factory);
			continue;
		}

		const refinement = refinements[key];
		if (refinement !== undefined && typeof refinement !== 'function') {
			columnSchemas[key] = refinement;
			continue;
		}

		const column = is(selected, Column) ? selected : undefined;
		const schema = column ? columnToSchema(column, factory?.typeboxInstance ?? t) : t.Any();
		const refined = typeof refinement === 'function' ? refinement(schema) : schema;

		if (conditions.never(column)) {
			continue;
		} else {
			columnSchemas[key] = refined;
		}

		if (column) {
			if (conditions.nullable(column)) {
				columnSchemas[key] = t.Union([columnSchemas[key]!, t.Null()]);
			}

			if (conditions.optional(column)) {
				columnSchemas[key] = t.Optional(columnSchemas[key]!);
			}
		}
	}

	return t.Object(columnSchemas) as any;
}

Subdomains

Frequently Asked Questions

What does handleColumns() do?
handleColumns() is a function in the drizzle-orm codebase, defined in drizzle-typebox/src/schema.ts.
Where is handleColumns() defined?
handleColumns() is defined in drizzle-typebox/src/schema.ts at line 20.
What does handleColumns() call?
handleColumns() calls 2 function(s): columnToSchema, getColumns.
What calls handleColumns()?
handleColumns() is called by 4 function(s): createInsertSchema, createSchemaFactory, createSelectSchema, createUpdateSchema.

Analyze Your Own Codebase

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

Try Supermodel Free