stringColumnToSchema() — drizzle-orm Function Reference
Architecture documentation for the stringColumnToSchema() function in column.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 99a086c8_b913_2bf5_4ffe_aec1d7ef74f8["stringColumnToSchema()"] d3d3a2d1_4197_a39b_12f9_f9c7be54febc["column.ts"] 99a086c8_b913_2bf5_4ffe_aec1d7ef74f8 -->|defined in| d3d3a2d1_4197_a39b_12f9_f9c7be54febc 85adcc4b_0e8e_a2e6_a538_afbe19c96304["columnToSchema()"] 85adcc4b_0e8e_a2e6_a538_afbe19c96304 -->|calls| 99a086c8_b913_2bf5_4ffe_aec1d7ef74f8 style 99a086c8_b913_2bf5_4ffe_aec1d7ef74f8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-zod/src/column.ts lines 267–319
function stringColumnToSchema(
column: Column,
z: typeof zod,
coerce: CreateSchemaFactoryOptions<
Partial<Record<'bigint' | 'boolean' | 'date' | 'number' | 'string', true>> | true | undefined
>['coerce'],
): zod.ZodType {
if (isColumnType<PgUUID<ColumnBaseConfig<'string', 'PgUUID'>>>(column, ['PgUUID'])) {
return z.uuid();
}
let max: number | undefined;
let regex: RegExp | undefined;
let fixed = false;
if (isColumnType<PgVarchar<any> | SQLiteText<any>>(column, ['PgVarchar', 'SQLiteText'])) {
max = column.length;
} else if (
isColumnType<MySqlVarChar<any> | SingleStoreVarChar<any>>(column, ['MySqlVarChar', 'SingleStoreVarChar'])
) {
max = column.length ?? CONSTANTS.INT16_UNSIGNED_MAX;
} else if (isColumnType<MySqlText<any> | SingleStoreText<any>>(column, ['MySqlText', 'SingleStoreText'])) {
if (column.textType === 'longtext') {
max = CONSTANTS.INT32_UNSIGNED_MAX;
} else if (column.textType === 'mediumtext') {
max = CONSTANTS.INT24_UNSIGNED_MAX;
} else if (column.textType === 'text') {
max = CONSTANTS.INT16_UNSIGNED_MAX;
} else {
max = CONSTANTS.INT8_UNSIGNED_MAX;
}
}
if (
isColumnType<PgChar<any> | MySqlChar<any> | SingleStoreChar<any>>(column, [
'PgChar',
'MySqlChar',
'SingleStoreChar',
])
) {
max = column.length;
fixed = true;
}
if (isColumnType<PgBinaryVector<any>>(column, ['PgBinaryVector'])) {
regex = /^[01]+$/;
max = column.dimensions;
}
let schema = coerce === true || coerce?.string ? z.coerce.string() : z.string();
schema = regex ? schema.regex(regex) : schema;
return max && fixed ? schema.length(max) : max ? schema.max(max) : schema;
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does stringColumnToSchema() do?
stringColumnToSchema() is a function in the drizzle-orm codebase, defined in drizzle-zod/src/column.ts.
Where is stringColumnToSchema() defined?
stringColumnToSchema() is defined in drizzle-zod/src/column.ts at line 267.
What calls stringColumnToSchema()?
stringColumnToSchema() is called by 1 function(s): columnToSchema.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free