mapDefault() — drizzle-orm Function Reference
Architecture documentation for the mapDefault() function in introspect-gel.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 2d45ec70_8e8a_7cb2_16e2_1b050ad1b5e0["mapDefault()"] ac795a29_c480_454a_c930_ea8898cad46c["introspect-gel.ts"] 2d45ec70_8e8a_7cb2_16e2_1b050ad1b5e0 -->|defined in| ac795a29_c480_454a_c930_ea8898cad46c eca90b4e_5154_72f2_c38f_cac24c3036e0["createTableColumns()"] eca90b4e_5154_72f2_c38f_cac24c3036e0 -->|calls| 2d45ec70_8e8a_7cb2_16e2_1b050ad1b5e0 6ab6e8e9_d4cc_9f6a_653a_f200196098f8["buildArrayDefault()"] 2d45ec70_8e8a_7cb2_16e2_1b050ad1b5e0 -->|calls| 6ab6e8e9_d4cc_9f6a_653a_f200196098f8 610207c4_fc50_760f_1018_68fe9d98e7f5["mapColumnDefault()"] 2d45ec70_8e8a_7cb2_16e2_1b050ad1b5e0 -->|calls| 610207c4_fc50_760f_1018_68fe9d98e7f5 b79b7789_7dc7_8d59_d31c_04fd15a06eee["unescapeSingleQuotes()"] 2d45ec70_8e8a_7cb2_16e2_1b050ad1b5e0 -->|calls| b79b7789_7dc7_8d59_d31c_04fd15a06eee style 2d45ec70_8e8a_7cb2_16e2_1b050ad1b5e0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-kit/src/introspect-gel.ts lines 551–696
const mapDefault = (
tableName: string,
type: string,
name: string,
enumTypes: Set<string>,
typeSchema: string,
defaultValue?: any,
internals?: GelKitInternals,
) => {
const isExpression = internals?.tables[tableName]?.columns[name]?.isDefaultAnExpression ?? false;
const isArray = internals?.tables[tableName]?.columns[name]?.isArray ?? false;
const lowered = type.toLowerCase().replace('[]', '');
if (name === 'id') {
return `.default(sql\`uuid_generate_v4()\`)`;
}
if (isArray) {
return typeof defaultValue !== 'undefined' ? `.default(${buildArrayDefault(defaultValue, lowered)})` : '';
}
if (enumTypes.has(`${typeSchema}.${type.replace('[]', '')}`)) {
return typeof defaultValue !== 'undefined'
? `.default(${mapColumnDefault(unescapeSingleQuotes(defaultValue, true), isExpression)})`
: '';
}
if (lowered.startsWith('integer')) {
return typeof defaultValue !== 'undefined'
? `.default(${mapColumnDefault(defaultValue.replaceAll('(', '').replaceAll(')', ''), isExpression)})`
: '';
}
if (lowered.startsWith('smallint')) {
return typeof defaultValue !== 'undefined'
? `.default(${mapColumnDefault(defaultValue.replaceAll('(', '').replaceAll(')', ''), isExpression)})`
: '';
}
if (lowered.startsWith('bigint')) {
return typeof defaultValue !== 'undefined'
? `.default(${mapColumnDefault(defaultValue.replaceAll('(', '').replaceAll(')', ''), isExpression)})`
: '';
}
if (lowered.startsWith('edgedbt.bigint_t')) {
return typeof defaultValue !== 'undefined'
? `.default(BigInt(${mapColumnDefault(defaultValue.replaceAll('(', '').replaceAll(')', ''), isExpression)}))`
: '';
}
if (lowered.startsWith('boolean')) {
return typeof defaultValue !== 'undefined' ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : '';
}
if (lowered.startsWith('double precision')) {
return typeof defaultValue !== 'undefined' ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : '';
}
if (lowered.startsWith('edgedbt.date_duration_t')) {
return typeof defaultValue !== 'undefined' ? `.default(${mapColumnDefault(defaultValue, true)})` : '';
}
if (lowered.startsWith('real')) {
return typeof defaultValue !== 'undefined' ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : '';
}
if (lowered.startsWith('uuid')) {
const res = defaultValue === 'gen_random_uuid()'
? '.defaultRandom()'
: defaultValue
? `.default(sql\`${defaultValue}\`)`
: '';
return res;
}
if (lowered.startsWith('numeric')) {
defaultValue = defaultValue
? (defaultValue.startsWith(`'`) && defaultValue.endsWith(`'`)
? defaultValue.substring(1, defaultValue.length - 1)
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does mapDefault() do?
mapDefault() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/introspect-gel.ts.
Where is mapDefault() defined?
mapDefault() is defined in drizzle-kit/src/introspect-gel.ts at line 551.
What does mapDefault() call?
mapDefault() calls 3 function(s): buildArrayDefault, mapColumnDefault, unescapeSingleQuotes.
What calls mapDefault()?
mapDefault() is called by 1 function(s): createTableColumns.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free