import { BaseSmartTags, PgColumn, PgFkColumn, PgTable, PgType, } from '../../abstractions'; import { buildName } from '../pg-sql-gen-utils'; export class VirtualFkColumn implements PgFkColumn { name: string; readonly table: PgTable; readonly type: PgType; readonly additionalStatements: string[] = []; readonly targetPk: PgColumn; constructor(targetPk: PgColumn, table: PgTable) { this.targetPk = targetPk; this.name = buildName(targetPk.table.name, targetPk.name); // Right now we just assume that all content types have the same PK type. this.type = targetPk.type; this.table = table; } buildSmartTags(): BaseSmartTags { return {}; } buildExpression(): string { return `${this.name} ${this.type}`; } buildAdditionalStatements(): string[] { return [`CREATE INDEX ON ${this.table.buildFullName()} (${this.name})`]; } }