-
Notifications
You must be signed in to change notification settings - Fork 128
/
factory.ts
26 lines (25 loc) · 1.02 KB
/
factory.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
import { MongoDBConnector, MongoDBOptions } from "./mongodb-connector.ts";
import { SQLite3Connector, SQLite3Options } from "./sqlite3-connector.ts";
import { MySQLConnector, MySQLOptions } from "./mysql-connector.ts";
import { PostgresConnector, PostgresOptions } from "./postgres-connector.ts";
import type { BuiltInDatabaseDialect } from "../database.ts";
import { Connector, ConnectorOptions } from "./connector.ts";
export function connectorFactory(
dialect: BuiltInDatabaseDialect,
connectionOptions: ConnectorOptions,
): Connector {
switch (dialect) {
case "mongo":
return new MongoDBConnector(connectionOptions as MongoDBOptions);
case "sqlite3":
return new SQLite3Connector(connectionOptions as SQLite3Options);
case "mysql":
return new MySQLConnector(connectionOptions as MySQLOptions);
case "postgres":
return new PostgresConnector(connectionOptions as PostgresOptions);
default:
throw new Error(
`No connector was found for the given dialect: ${dialect}.`,
);
}
}