-
Notifications
You must be signed in to change notification settings - Fork 280
/
database-introspector.ts
69 lines (59 loc) · 1.68 KB
/
database-introspector.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* An interface for getting the database metadata (names of the tables and columns etc.)
*/
export interface DatabaseIntrospector {
/**
* Get schema metadata.
*/
getSchemas(): Promise<SchemaMetadata[]>
/**
* Get table metadata.
*/
getTables(options?: DatabaseMetadataOptions): Promise<TableMetadata[]>
/**
* Get the database metadata such as table and column names.
*
* @deprecated Use getTables() instead.
*/
getMetadata(options?: DatabaseMetadataOptions): Promise<DatabaseMetadata>
}
export interface DatabaseMetadataOptions {
/**
* If this is true, the metadata contains the internal kysely tables
* such as the migration tables.
*/
withInternalKyselyTables: boolean
}
export interface SchemaMetadata {
readonly name: string
}
export interface DatabaseMetadata {
/**
* The tables found in the database.
*/
readonly tables: TableMetadata[]
}
export interface TableMetadata {
readonly name: string
readonly columns: ColumnMetadata[]
readonly schema?: string
}
export interface ColumnMetadata {
readonly name: string
/**
* The data type of the column as reported by the database.
*
* NOTE: This value is whatever the database engine returns and it will be
* different on different dialects even if you run the same migrations.
* For example `integer` datatype in a migration will produce `int4`
* on PostgreSQL, `INTEGER` on SQLite and `int` on MySQL.
*/
readonly dataType: string
/**
* The schema this column's data type was created in.
*/
readonly dataTypeSchema?: string
readonly isAutoIncrementing: boolean
readonly isNullable: boolean
readonly hasDefaultValue: boolean
}