-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
DriverFactory.ts
95 lines (94 loc) · 3.7 KB
/
DriverFactory.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { MissingDriverError } from "../error/MissingDriverError"
import { CockroachDriver } from "./cockroachdb/CockroachDriver"
import { MongoDriver } from "./mongodb/MongoDriver"
import { SqlServerDriver } from "./sqlserver/SqlServerDriver"
import { OracleDriver } from "./oracle/OracleDriver"
import { SqliteDriver } from "./sqlite/SqliteDriver"
import { CordovaDriver } from "./cordova/CordovaDriver"
import { ReactNativeDriver } from "./react-native/ReactNativeDriver"
import { NativescriptDriver } from "./nativescript/NativescriptDriver"
import { SqljsDriver } from "./sqljs/SqljsDriver"
import { MysqlDriver } from "./mysql/MysqlDriver"
import { PostgresDriver } from "./postgres/PostgresDriver"
import { ExpoDriver } from "./expo/ExpoDriver"
import { AuroraMysqlDriver } from "./aurora-mysql/AuroraMysqlDriver"
import { AuroraPostgresDriver } from "./aurora-postgres/AuroraPostgresDriver"
import { Driver } from "./Driver"
import { DataSource } from "../data-source/DataSource"
import { SapDriver } from "./sap/SapDriver"
import { BetterSqlite3Driver } from "./better-sqlite3/BetterSqlite3Driver"
import { CapacitorDriver } from "./capacitor/CapacitorDriver"
import { SpannerDriver } from "./spanner/SpannerDriver"
/**
* Helps to create drivers.
*/
export class DriverFactory {
/**
* Creates a new driver depend on a given connection's driver type.
*/
create(connection: DataSource): Driver {
const { type } = connection.options
switch (type) {
case "mysql":
return new MysqlDriver(connection)
case "postgres":
return new PostgresDriver(connection)
case "cockroachdb":
return new CockroachDriver(connection)
case "sap":
return new SapDriver(connection)
case "mariadb":
return new MysqlDriver(connection)
case "sqlite":
return new SqliteDriver(connection)
case "better-sqlite3":
return new BetterSqlite3Driver(connection)
case "cordova":
return new CordovaDriver(connection)
case "nativescript":
return new NativescriptDriver(connection)
case "react-native":
return new ReactNativeDriver(connection)
case "sqljs":
return new SqljsDriver(connection)
case "oracle":
return new OracleDriver(connection)
case "mssql":
return new SqlServerDriver(connection)
case "mongodb":
return new MongoDriver(connection)
case "expo":
return new ExpoDriver(connection)
case "aurora-mysql":
return new AuroraMysqlDriver(connection)
case "aurora-postgres":
return new AuroraPostgresDriver(connection)
case "capacitor":
return new CapacitorDriver(connection)
case "spanner":
return new SpannerDriver(connection)
default:
throw new MissingDriverError(type, [
"aurora-mysql",
"aurora-postgres",
"better-sqlite3",
"capacitor",
"cockroachdb",
"cordova",
"expo",
"mariadb",
"mongodb",
"mssql",
"mysql",
"nativescript",
"oracle",
"postgres",
"react-native",
"sap",
"sqlite",
"sqljs",
"spanner",
])
}
}
}