forked from drizzle-team/drizzle-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.ts
40 lines (33 loc) · 1.07 KB
/
schema.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
33
34
35
36
37
38
39
40
import { entityKind, is } from '~/entity';
import { type MySqlTableFn, mysqlTableWithSchema } from './table';
import { type mysqlView, mysqlViewWithSchema } from './view';
export class MySqlSchema<TName extends string = string> {
static readonly [entityKind]: string = 'MySqlSchema';
constructor(
public readonly schemaName: TName,
) {}
table: MySqlTableFn<TName> = (name, columns, extraConfig) => {
return mysqlTableWithSchema(name, columns, extraConfig, this.schemaName);
};
view = ((name, columns) => {
return mysqlViewWithSchema(name, columns, this.schemaName);
}) as typeof mysqlView;
}
/** @deprecated - use `instanceof MySqlSchema` */
export function isMySqlSchema(obj: unknown): obj is MySqlSchema {
return is(obj, MySqlSchema);
}
/**
* Create a MySQL schema.
* https://dev.mysql.com/doc/refman/8.0/en/create-database.html
*
* @param name mysql use schema name
* @returns MySQL schema
*/
export function mysqlDatabase<TName extends string>(name: TName) {
return new MySqlSchema(name);
}
/**
* @see mysqlDatabase
*/
export const mysqlSchema = mysqlDatabase;