-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathDelete.swift
More file actions
59 lines (52 loc) · 1.46 KB
/
Delete.swift
File metadata and controls
59 lines (52 loc) · 1.46 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Delete.swift
// PostgresStORM
//
// Created by Jonathan Guthrie on 2016-09-24.
//
//
import PerfectLib
import StORM
import PerfectLogger
/// Performs delete-specific functions as an extension
extension MySQLStORM {
func deleteSQL(_ table: String, idName: String = "id") -> String {
return "DELETE FROM \(table) WHERE \(idName) = ?"
}
/// Deletes one row, with an id as an integer
@discardableResult
public func delete(_ id: Int, idName: String = "id") throws -> Bool {
do {
try exec(deleteSQL(self.table(), idName: idName), params: [String(id)])
} catch {
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
return true
}
/// Deletes one row, with an id as a String
@discardableResult
public func delete(_ id: String, idName: String = "id") throws -> Bool {
do {
try exec(deleteSQL(self.table(), idName: idName), params: [id])
} catch {
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
return true
}
/// Deletes one row, with an id as a UUID
@discardableResult
public func delete(_ id: UUID, idName: String = "id") throws -> Bool {
do {
try exec(deleteSQL(self.table(), idName: idName), params: [id.string])
} catch {
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
return true
}
}