1 5
import {MissingDriverError} from "../error/MissingDriverError";
2 5
import {CockroachDriver} from "./cockroachdb/CockroachDriver";
3 5
import {MongoDriver} from "./mongodb/MongoDriver";
4 5
import {SqlServerDriver} from "./sqlserver/SqlServerDriver";
5 5
import {OracleDriver} from "./oracle/OracleDriver";
6 5
import {SqliteDriver} from "./sqlite/SqliteDriver";
7 5
import {CordovaDriver} from "./cordova/CordovaDriver";
8 5
import {ReactNativeDriver} from "./react-native/ReactNativeDriver";
9 5
import {NativescriptDriver} from "./nativescript/NativescriptDriver";
10 5
import {SqljsDriver} from "./sqljs/SqljsDriver";
11 5
import {MysqlDriver} from "./mysql/MysqlDriver";
12 5
import {PostgresDriver} from "./postgres/PostgresDriver";
13 5
import {ExpoDriver} from "./expo/ExpoDriver";
14 5
import {AuroraDataApiDriver} from "./aurora-data-api/AuroraDataApiDriver";
15 5
import {AuroraDataApiPostgresDriver} from "./aurora-data-api-pg/AuroraDataApiPostgresDriver";
16
import {Driver} from "./Driver";
17
import {Connection} from "../connection/Connection";
18 5
import {SapDriver} from "./sap/SapDriver";
19 5
import {BetterSqlite3Driver} from "./better-sqlite3/BetterSqlite3Driver";
20

21
/**
22
 * Helps to create drivers.
23
 */
24 5
export class DriverFactory {
25

26
    /**
27
     * Creates a new driver depend on a given connection's driver type.
28
     */
29 5
    create(connection: Connection): Driver {
30 5
        const {type} = connection.options;
31 5
        switch (type) {
32 5
            case "mysql":
33 5
                return new MysqlDriver(connection);
34 3
            case "postgres":
35 3
                return new PostgresDriver(connection);
36 1
            case "cockroachdb":
37 1
                return new CockroachDriver(connection);
38 0
            case "sap":
39 0
                return new SapDriver(connection);
40 3
            case "mariadb":
41 3
                return new MysqlDriver(connection);
42 5
            case "sqlite":
43 5
                return new SqliteDriver(connection);
44 5
            case "better-sqlite3":
45 5
                return new BetterSqlite3Driver(connection);
46 0
            case "cordova":
47 0
                return new CordovaDriver(connection);
48 0
            case "nativescript":
49 0
                return new NativescriptDriver(connection);
50 0
            case "react-native":
51 0
                return new ReactNativeDriver(connection);
52 3
            case "sqljs":
53 3
                return new SqljsDriver(connection);
54 1
            case "oracle":
55 1
                return new OracleDriver(connection);
56 3
            case "mssql":
57 3
                return new SqlServerDriver(connection);
58 3
            case "mongodb":
59 3
                return new MongoDriver(connection);
60 0
            case "expo":
61 0
                return new ExpoDriver(connection);
62 0
            case "aurora-data-api":
63 0
                return new AuroraDataApiDriver(connection);
64 0
            case "aurora-data-api-pg":
65 0
                return new AuroraDataApiPostgresDriver(connection);
66 0
            default:
67 0
                throw new MissingDriverError(type);
68
        }
69
    }
70

71 5
}

Read our documentation on viewing source code .

Loading