import { BaseSmartTags, PgColumn, PgTable, PgType } from '../../abstractions'; export interface PrimitiveColumnOptions { description?: string; indexable?: boolean; extraParams?: string; } /** * Database column of primitive type. */ export class PrimitiveColumn implements PgColumn { name: string; displayName?: string; readonly description?: string; readonly table: PgTable; readonly type: PgType; private columnOptions?: PrimitiveColumnOptions; constructor( name: string, type: PgType, table: PgTable, options?: PrimitiveColumnOptions, ) { this.name = name; this.description = options?.description; this.table = table; this.type = type; this.columnOptions = options; } buildExpression(): string { const baseExpression = `${this.name} ${this.type}`; if (this.columnOptions?.extraParams) { return `${baseExpression} ${this.columnOptions.extraParams}`; } return baseExpression; } buildAdditionalStatements(): string[] { if (this.columnOptions?.indexable) { return [`CREATE INDEX ON ${this.table.buildFullName()} (${this.name})`]; } return []; } buildSmartTags(): BaseSmartTags { const tags: BaseSmartTags = { description: this.description, }; if (this.displayName) { tags.tags = { name: this.displayName, }; } return tags; } }