createTableIndexes() — drizzle-orm Function Reference
Architecture documentation for the createTableIndexes() function in introspect-pg.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 6654cdae_b135_ed6d_5743_767fc7ed226e["createTableIndexes()"] 71516551_23e3_bf30_27c9_000fb046ef71["introspect-pg.ts"] 6654cdae_b135_ed6d_5743_767fc7ed226e -->|defined in| 71516551_23e3_bf30_27c9_000fb046ef71 ae4bc88a_1e24_ce7b_ea80_728e39b829ef["schemaToTypeScript()"] ae4bc88a_1e24_ce7b_ea80_728e39b829ef -->|calls| 6654cdae_b135_ed6d_5743_767fc7ed226e 968467a1_c4a6_11cb_5fbc_8854071f9af4["withCasing()"] 6654cdae_b135_ed6d_5743_767fc7ed226e -->|calls| 968467a1_c4a6_11cb_5fbc_8854071f9af4 style 6654cdae_b135_ed6d_5743_767fc7ed226e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-kit/src/introspect-pg.ts lines 1201–1257
const createTableIndexes = (tableName: string, idxs: Index[], casing: Casing): string => {
let statement = '';
idxs.forEach((it) => {
// we have issue when index is called as table called
let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
idxKey = idxKey.endsWith('_index') ? idxKey.slice(0, -'_index'.length) + '_idx' : idxKey;
idxKey = withCasing(idxKey, casing);
const indexGeneratedName = indexName(
tableName,
it.columns.map((it) => it.expression),
);
const escapedIndexName = indexGeneratedName === it.name ? '' : `"${it.name}"`;
statement += `\n\t`;
statement += it.isUnique ? 'uniqueIndex(' : 'index(';
statement += `${escapedIndexName})`;
statement += `${it.concurrently ? `.concurrently()` : ''}`;
statement += `.using("${it.method}", ${
it.columns
.map((it) => {
if (it.isExpression) {
return `sql\`${it.expression}\``;
} else {
return `table.${withCasing(it.expression, casing)}${it.asc ? '.asc()' : '.desc()'}${
it.nulls === 'first' ? '.nullsFirst()' : '.nullsLast()'
}${
it.opclass
? `.op("${it.opclass}")`
: ''
}`;
}
})
.join(', ')
})`;
statement += it.where ? `.where(sql\`${it.where}\`)` : '';
function reverseLogic(mappedWith: Record<string, string>): string {
let reversedString = '{';
for (const key in mappedWith) {
if (mappedWith.hasOwnProperty(key)) {
reversedString += `${key}: "${mappedWith[key]}",`;
}
}
reversedString = reversedString.length > 1 ? reversedString.slice(0, reversedString.length - 1) : reversedString;
return `${reversedString}}`;
}
statement += it.with && Object.keys(it.with).length > 0 ? `.with(${reverseLogic(it.with)})` : '';
statement += `,`;
});
return statement;
};
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does createTableIndexes() do?
createTableIndexes() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/introspect-pg.ts.
Where is createTableIndexes() defined?
createTableIndexes() is defined in drizzle-kit/src/introspect-pg.ts at line 1201.
What does createTableIndexes() call?
createTableIndexes() calls 1 function(s): withCasing.
What calls createTableIndexes()?
createTableIndexes() is called by 1 function(s): schemaToTypeScript.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free