-
-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathIOSDriverFactory.swift
More file actions
45 lines (43 loc) · 1.53 KB
/
IOSDriverFactory.swift
File metadata and controls
45 lines (43 loc) · 1.53 KB
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
import Foundation
import TableProDatabase
import TableProModels
final class IOSDriverFactory: DriverFactory {
func createDriver(for connection: DatabaseConnection, password: String?) throws -> any DatabaseDriver {
switch connection.type {
case .sqlite:
return SQLiteDriver(path: connection.database)
case .mysql, .mariadb:
return MySQLDriver(
host: connection.host,
port: connection.port,
user: connection.username,
password: password ?? "",
database: connection.database,
sslEnabled: connection.sslEnabled
)
case .postgresql, .redshift:
return PostgreSQLDriver(
host: connection.host,
port: connection.port,
user: connection.username,
password: password ?? "",
database: connection.database,
sslEnabled: connection.sslEnabled
)
case .redis:
let dbIndex = Int(connection.database) ?? 0
return RedisDriver(
host: connection.host,
port: connection.port,
password: password,
database: dbIndex,
sslEnabled: connection.sslEnabled
)
default:
throw ConnectionError.driverNotFound(connection.type.rawValue)
}
}
func supportedTypes() -> [DatabaseType] {
[.sqlite, .mysql, .mariadb, .postgresql, .redshift, .redis]
}
}