-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSQLiteConnect.swift
More file actions
48 lines (40 loc) · 923 Bytes
/
SQLiteConnect.swift
File metadata and controls
48 lines (40 loc) · 923 Bytes
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
//
// SQLiteConnect.swift
// SQLiteStORM
//
// Created by Jonathan Guthrie on 2016-09-23.
//
//
import StORM
import PerfectSQLite
import PerfectLogger
/// Base connector class, inheriting from StORMConnect.
/// Provides connection services for the Database Provider
open class SQLiteConnect: StORMConnect {
/// Init with no credentials
override init() {
super.init()
self.datasource = .SQLite
}
/// Init with credentials
public init(_ path: String) {
super.init()
self.database = path
self.datasource = .SQLite
}
/// Opens the database file
/// Returns a SQLite object
public func open() throws -> SQLite {
do {
let db = try SQLite(self.database)
return db
} catch {
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
/// Closes the connection to the database file
public func close(_ db: SQLite) {
db.close()
}
}