MCPcopy Create free account
hub / github.com/subquery/subql / generateCreateIndexQuery

Function generateCreateIndexQuery

packages/node-core/src/db/sync-helper.ts:530–547  ·  view source on GitHub ↗
(
  indexes: readonly ModelIndexesOptions[],
  schema: string,
  tableName: string
)

Source from the content-addressed store, hash-verified

528}
529
530export function generateCreateIndexQuery(
531 indexes: readonly ModelIndexesOptions[],
532 schema: string,
533 tableName: string
534): string[] {
535 const indexQueries: string[] = [];
536 indexes.forEach((index) => {
537 const fieldsList = index.fields?.map((field) => `"${field}"`).join(', ');
538 const unique = index.unique ? 'UNIQUE' : '';
539 const indexUsed = index.using ? `USING ${index.using}` : '';
540 const indexName = index.name;
541
542 const query = `CREATE ${unique} INDEX IF NOT EXISTS "${indexName}" ON "${schema}"."${tableName}" ${indexUsed} (${fieldsList});`;
543 indexQueries.push(query);
544 });
545
546 return indexQueries;
547}
548
549export function sortModels(relations: GraphQLRelationsType[], models: GraphQLModelsType[]): GraphQLModelsType[] | null {
550 const sorter = new Toposort();

Callers 1

Calls 1

mapMethod · 0.80

Tested by

no test coverage detected