Store sharing key instead of just a bool

This commit is contained in:
relikd
2020-08-28 23:41:08 +02:00
parent c502484bcf
commit b03daeca66
5 changed files with 35 additions and 20 deletions

View File

@@ -26,7 +26,7 @@ extension SQLiteDatabase {
if version == 1 {
transaction("""
ALTER TABLE rec ADD COLUMN subtitle TEXT;
ALTER TABLE rec ADD COLUMN opt INTEGER;
ALTER TABLE rec ADD COLUMN sharekey TEXT;
""")
}
try run(sql: "PRAGMA user_version = 2;")
@@ -298,12 +298,12 @@ extension CreateTable {
title TEXT,
subtitle TEXT,
notes TEXT,
opt INTEGER
sharekey TEXT
);
"""}
}
let readRecordingSelect = "id, start, stop, appid, title, subtitle, notes, opt"
let readRecordingSelect = "id, start, stop, appid, title, subtitle, notes, sharekey"
struct Recording {
let id: sqlite3_int64
let start: Timestamp
@@ -312,7 +312,7 @@ struct Recording {
var title: String? = nil
var subtitle: String? = nil
var notes: String? = nil
var shared: Bool = false
var sharekey: String? = nil
}
typealias AppBundleInfo = (bundleId: String, name: String?, author: String?)
@@ -341,9 +341,9 @@ extension SQLiteDatabase {
/// Update given recording by replacing `title`, `appid`, and `notes` with new values.
func recordingUpdate(_ r: Recording) {
try? run(sql: "UPDATE rec SET appid = ?, title = ?, subtitle = ?, notes = ?, opt = ? WHERE id = ? LIMIT 1;",
try? run(sql: "UPDATE rec SET appid = ?, title = ?, subtitle = ?, notes = ?, sharekey = ? WHERE id = ? LIMIT 1;",
bind: [BindTextOrNil(r.appId), BindTextOrNil(r.title), BindTextOrNil(r.subtitle),
BindTextOrNil(r.notes), r.shared ? BindInt32(1) : BindNull(), BindInt64(r.id)]) { stmt -> Void in
BindTextOrNil(r.notes), BindTextOrNil(r.sharekey), BindInt64(r.id)]) { stmt -> Void in
sqlite3_step(stmt)
}
}
@@ -362,7 +362,6 @@ extension SQLiteDatabase {
private func readRecording(_ stmt: OpaquePointer) -> Recording {
let end = col_ts(stmt, 2)
let opt = sqlite3_column_int(stmt, 7)
return Recording(id: sqlite3_column_int64(stmt, 0),
start: col_ts(stmt, 1),
stop: end == 0 ? nil : end,
@@ -370,7 +369,7 @@ extension SQLiteDatabase {
title: col_text(stmt, 4),
subtitle: col_text(stmt, 5),
notes: col_text(stmt, 6),
shared: opt > 0)
sharekey: col_text(stmt, 7))
}
/// `WHERE stop IS NULL`

View File

@@ -38,5 +38,6 @@ extension Recording {
} }
var duration: Timestamp? { get { stop == nil ? nil : stop! - start } }
var isLongTerm: Bool { (duration ?? 0) > Timestamp.hours(1) }
var isShared: Bool { sharekey?.count ?? 0 > 0}
}