schemaToTypeScript() — drizzle-orm Function Reference
Architecture documentation for the schemaToTypeScript() function in introspect-gel.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD d6ed66aa_aafe_f478_835c_7c02934633eb["schemaToTypeScript()"] ac795a29_c480_454a_c930_ea8898cad46c["introspect-gel.ts"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|defined in| ac795a29_c480_454a_c930_ea8898cad46c 13b884c4_04ee_3a07_de49_bfbf8819424d["withCasing()"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|calls| 13b884c4_04ee_3a07_de49_bfbf8819424d a7f5c7a2_3cd7_5521_1f7d_dc2892c7fb5b["isCyclic()"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|calls| a7f5c7a2_3cd7_5521_1f7d_dc2892c7fb5b 88bf53ff_cff7_eb87_a692_a90b044f574b["isSelf()"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|calls| 88bf53ff_cff7_eb87_a692_a90b044f574b 75b32510_d64f_63b3_5a7e_75ed201613df["paramNameFor()"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|calls| 75b32510_d64f_63b3_5a7e_75ed201613df b79b7789_7dc7_8d59_d31c_04fd15a06eee["unescapeSingleQuotes()"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|calls| b79b7789_7dc7_8d59_d31c_04fd15a06eee eca90b4e_5154_72f2_c38f_cac24c3036e0["createTableColumns()"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|calls| eca90b4e_5154_72f2_c38f_cac24c3036e0 a67e3b98_8cdf_2b03_13e5_11238cda3b65["createTableIndexes()"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|calls| a67e3b98_8cdf_2b03_13e5_11238cda3b65 038eef43_b327_d03b_1631_0ab1345e5067["createTableFKs()"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|calls| 038eef43_b327_d03b_1631_0ab1345e5067 8487dd1d_2748_1c05_0f9d_86ea7c0888d7["createTablePKs()"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|calls| 8487dd1d_2748_1c05_0f9d_86ea7c0888d7 35b98027_9ad8_d390_f5d0_6c4cbe056bb0["createTableUniques()"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|calls| 35b98027_9ad8_d390_f5d0_6c4cbe056bb0 fa9ff7be_dc3f_2f25_835c_09506519ceba["createTablePolicies()"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|calls| fa9ff7be_dc3f_2f25_835c_09506519ceba 4e2c039b_2266_9576_a8a8_97776a1c780b["createTableChecks()"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|calls| 4e2c039b_2266_9576_a8a8_97776a1c780b 893ac5b5_2ea6_d9e5_8c08_453ea1789956["camelCase()"] d6ed66aa_aafe_f478_835c_7c02934633eb -->|calls| 893ac5b5_2ea6_d9e5_8c08_453ea1789956 style d6ed66aa_aafe_f478_835c_7c02934633eb fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-kit/src/introspect-gel.ts lines 211–520
export const schemaToTypeScript = (schema: GelSchemaInternal, casing: Casing) => {
// collectFKs
Object.values(schema.tables).forEach((table) => {
Object.values(table.foreignKeys).forEach((fk) => {
const relation = `${fk.tableFrom}-${fk.tableTo}`;
relations.add(relation);
});
});
const schemas = Object.fromEntries(
Object.entries(schema.schemas).map((it) => {
return [it[0], withCasing(it[1].replace('::', ''), casing)];
}),
);
// const enumTypes = Object.values(schema.enums).reduce((acc, cur) => {
// acc.add(`${cur.schema}.${cur.name}`);
// return acc;
// }, new Set<string>());
const imports = Object.values(schema.tables).reduce(
(res, it) => {
const idxImports = Object.values(it.indexes).map((idx) => (idx.isUnique ? 'uniqueIndex' : 'index'));
const fkImpots = Object.values(it.foreignKeys).map((it) => 'foreignKey');
if (Object.values(it.foreignKeys).some((it) => isCyclic(it) && !isSelf(it))) {
res.gel.push('type AnyGelColumn');
}
const pkImports = Object.values(it.compositePrimaryKeys).map((it) => 'primaryKey');
const uniqueImports = Object.values(it.uniqueConstraints).map((it) => 'unique');
const checkImports = Object.values(it.checkConstraints).map(
(it) => 'check',
);
const policiesImports = Object.values(it.policies).map(
(it) => 'gelPolicy',
);
if (it.schema && it.schema !== 'public' && it.schema !== '') {
res.gel.push('gelSchema');
}
res.gel.push(...idxImports);
res.gel.push(...fkImpots);
res.gel.push(...pkImports);
res.gel.push(...uniqueImports);
res.gel.push(...policiesImports);
res.gel.push(...checkImports);
const columnImports = Object.values(it.columns)
.map((col) => {
let patched: string = col.type?.replace('[]', '') ?? '';
patched = patched.startsWith('time without time zone') ? 'localTime' : patched;
patched = patched === 'double precision' ? 'doublePrecision' : patched;
patched = patched.startsWith('edgedbt.bigint_t') ? 'bigintT' : patched;
patched = patched.startsWith('jsonb') ? 'json' : patched;
patched = patched.startsWith('edgedbt.timestamptz_t') ? 'timestamptz' : patched;
patched = patched.startsWith('edgedbt.timestamp_t') ? 'timestamp' : patched;
patched = patched.startsWith('edgedbt.relative_duration_t') ? 'relDuration' : patched;
patched = patched.startsWith('bytea') ? 'bytes' : patched;
patched = patched.startsWith('numeric') ? 'decimal' : patched;
patched = patched.startsWith('edgedbt.duration_t') ? 'duration' : patched;
patched = patched.startsWith('edgedbt.date_t') ? 'localDate' : patched;
patched = patched.startsWith('edgedbt.date_duration_t') ? 'dateDuration' : patched;
return patched;
})
.filter((type) => {
return gelImportsList.has(type);
});
res.gel.push(...columnImports);
return res;
},
{ gel: [] as string[] },
);
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does schemaToTypeScript() do?
schemaToTypeScript() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/introspect-gel.ts.
Where is schemaToTypeScript() defined?
schemaToTypeScript() is defined in drizzle-kit/src/introspect-gel.ts at line 211.
What does schemaToTypeScript() call?
schemaToTypeScript() calls 14 function(s): camelCase, createTableChecks, createTableColumns, createTableFKs, createTableIndexes, createTablePKs, createTablePolicies, createTableUniques, and 6 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free