-
Notifications
You must be signed in to change notification settings - Fork 102
/
schema.ts
32 lines (28 loc) · 919 Bytes
/
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
import { Database } from './schemaInterfaces'
import { PostgresDatabase } from './schemaPostgres'
import { MysqlDatabase } from './schemaMysql'
enum SQLVersion {
POSTGRES = 1,
MYSQL = 2,
UNKNOWN = 3
}
function getSQLVersion (connection: string): SQLVersion {
if (/^postgres(ql)?:\/\//i.test(connection)) {
return SQLVersion.POSTGRES
} else if (/^mysql:\/\//i.test(connection)) {
return SQLVersion.MYSQL
} else {
return SQLVersion.UNKNOWN
}
}
export function getDatabase (connection: string): Database {
switch (getSQLVersion(connection)) {
case SQLVersion.MYSQL:
return new MysqlDatabase(connection)
case SQLVersion.POSTGRES:
return new PostgresDatabase(connection)
default:
throw new Error(`SQL version unsupported in connection: ${connection}`)
}
}
export {Database} from './schemaInterfaces'