Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 1x 1x 1x 34x 1x 1x 1x 34x 1x 1x | import { entityKind } from 'drizzle-orm/entity'
import { getTableName } from 'drizzle-orm/table'
import type { YdbColumn } from './columns/common.js'
import type { YdbTable } from './table.js'
function assertColumnsBelongToTable(table: YdbTable, columns: readonly YdbColumn[]): void {
let tableName = getTableName(table)
for (let column of columns) {
Iif (column.table !== table) {
throw new Error(
`Primary key column "${column.name}" does not belong to table "${tableName}"`
)
}
}
}
export interface YdbPrimaryKeyConfig {
readonly table: YdbTable
readonly columns: readonly YdbColumn[]
}
export class YdbPrimaryKeyBuilder {
static readonly [entityKind] = 'YdbPrimaryKeyBuilder'
constructor(private readonly columns: [YdbColumn, ...YdbColumn[]]) {}
build(table: YdbTable): YdbPrimaryKey {
assertColumnsBelongToTable(table, this.columns)
return new YdbPrimaryKey({
table,
columns: [...this.columns],
})
}
}
export class YdbPrimaryKey {
static readonly [entityKind] = 'YdbPrimaryKey'
constructor(readonly config: YdbPrimaryKeyConfig) {}
}
export function primaryKey(...columns: [YdbColumn, ...YdbColumn[]]): YdbPrimaryKeyBuilder {
return new YdbPrimaryKeyBuilder(columns)
}
|