Edit delete recordings

This commit is contained in:
relikd
2020-04-08 21:34:45 +02:00
parent d0056c0275
commit 80f3503e16
5 changed files with 52 additions and 10 deletions

View File

@@ -230,6 +230,7 @@ class DBWrapper {
func recordingStop(_ r: inout Recording) { AppDB?.stopRecording(&r) }
func recordingPersist(_ r: Recording) { AppDB?.persistRecordingLogs(r) }
func recordingDetails(_ r: Recording) -> [RecordLog] { AppDB?.getRecordingsLogs(r) ?? [] }
func recordingUpdate(_ r: Recording) {
AppDB?.updateRecording(r)
@@ -242,8 +243,8 @@ class DBWrapper {
}
}
func recordingDetails(_ r: Recording) -> [(domain: String?, count: Int32)]? {
AppDB?.getRecordingsLogs(r)
func recordingDeleteDetails(_ r: Recording, domain: String?) -> Bool {
((try? AppDB?.deleteRecordingLogs(r.id, matchingDomain: domain)) ?? 0) > 0
}

View File

@@ -441,9 +441,9 @@ extension SQLiteDatabase {
}
}
private func deleteRecordingLogs(_ recId: sqlite3_int64) throws -> Int32 {
try run(sql: "DELETE FROM recLog WHERE rid = ?;", bind: {
self.bindInt64($0, 1, recId)
func deleteRecordingLogs(_ recId: sqlite3_int64, matchingDomain d: String? = nil) throws -> Int32 {
try run(sql: "DELETE FROM recLog WHERE rid = ? \(d==nil ? "" : "AND domain = ?");", bind: {
self.bindInt64($0, 1, recId) && (d==nil ? true : self.bindTextOrNil($0, 2,d))
}) {
try ifStep($0, SQLITE_DONE)
return sqlite3_changes(dbPointer)
@@ -452,7 +452,7 @@ extension SQLiteDatabase {
// MARK: read
func getRecordingsLogs(_ r: Recording) -> [(domain: String?, count: Int32)]? {
func getRecordingsLogs(_ r: Recording) -> [RecordLog]? {
try? run(sql: "SELECT domain, COUNT() FROM recLog WHERE rid = ? GROUP BY domain;", bind: {
self.bindInt64($0, 1, r.id)
}) {
@@ -460,3 +460,5 @@ extension SQLiteDatabase {
}
}
}
typealias RecordLog = (domain: String?, count: Int32)