forked from drizzle-team/drizzle-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks.ts
32 lines (24 loc) · 767 Bytes
/
checks.ts
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
import { entityKind } from '~/entity';
import type { SQL } from '~/sql';
import type { AnyMySqlTable } from './table';
export class CheckBuilder {
static readonly [entityKind]: string = 'MySqlCheckBuilder';
protected brand!: 'MySqlConstraintBuilder';
constructor(public name: string, public value: SQL) {}
/** @internal */
build(table: AnyMySqlTable): Check {
return new Check(table, this);
}
}
export class Check {
static readonly [entityKind]: string = 'MySqlCheck';
readonly name: string;
readonly value: SQL;
constructor(public table: AnyMySqlTable, builder: CheckBuilder) {
this.name = builder.name;
this.value = builder.value;
}
}
export function check(name: string, value: SQL): CheckBuilder {
return new CheckBuilder(name, value);
}