MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / createIndex

Function createIndex

packages/sql/src/schema/SchemaHelper.ts:1086–1112  ·  view source on GitHub ↗
(index: IndexDef, table: DatabaseTable, createPrimary = false)

Source from the content-addressed store, hash-verified

1084 }
1085
1086 createIndex(index: IndexDef, table: DatabaseTable, createPrimary = false): string {
1087 if (index.primary && !createPrimary) {
1088 return '';
1089 }
1090
1091 if (index.expression) {
1092 return index.expression;
1093 }
1094
1095 const columns = index.columnNames.map(c => this.quote(c)).join(', ');
1096 const defer = index.deferMode ? ` deferrable initially ${index.deferMode}` : '';
1097
1098 if (index.primary) {
1099 const keyName = this.hasNonDefaultPrimaryKeyName(table) ? `constraint ${index.keyName} ` : '';
1100 return `alter table ${table.getQuotedName()} add ${keyName}primary key (${columns})${defer}`;
1101 }
1102
1103 if (index.type === 'fulltext') {
1104 const columns = index.columnNames.map(name => ({ name, type: table.getColumn(name)!.type }));
1105
1106 if (this.platform.supportsCreatingFullTextIndex()) {
1107 return this.platform.getFullTextIndexExpression(index.keyName, table.schema, table.name, columns);
1108 }
1109 }
1110
1111 return this.getCreateIndexSQL(table.getShortestName(), index);
1112 }
1113
1114 createCheck(table: DatabaseTable, check: CheckDef): string {
1115 const expression = check.expression as string;

Callers

nothing calls this directly

Calls 9

getQuotedNameMethod · 0.80
getColumnMethod · 0.80
getShortestNameMethod · 0.80
joinMethod · 0.65
mapMethod · 0.45
quoteMethod · 0.45
getCreateIndexSQLMethod · 0.45

Tested by

no test coverage detected