2024-01-21 14:32:00 +01:00

22 lines
636 B
Swift

import Foundation
import SQLite
struct DBMetadataKey {
private static let table = Table("metadata_keys")
private static let rowId = Expression<Int>("ROWID")
private static let rowKey = Expression<String>("key")
static func key(for keyId: Int, in database: Connection) throws -> String {
try database.prepare(table.filter(rowId == keyId).limit(1)).map { $0[rowKey] }.first!
}
static func readAll(in database: Connection) throws -> [ Int: String] {
try database.prepare(table).reduce(into: [:]) { dict, row in
dict[row[rowId]] = row[rowKey]
}
}
}