NetNewsWire/Frameworks/Database/AuthorsTable.swift

48 lines
816 B
Swift
Raw Normal View History

2017-07-13 22:38:47 +02:00
//
// AuthorsTable.swift
2017-07-13 22:38:47 +02:00
// Database
//
// Created by Brent Simmons on 7/13/17.
// Copyright © 2017 Ranchero Software. All rights reserved.
//
import Foundation
import Data
final class AuthorsTable: DatabaseTable {
let name: String
init(name: String) {
self.name = name
}
2017-07-13 22:38:47 +02:00
var cachedAuthors = [String: Author]()
func cachedAuthor(_ databaseID: String) -> Author? {
return cachedAuthors[databaseID]
}
func cacheAuthor(_ author: Author) {
cachedAuthors[author.databaseID] = author
}
func authorWithRow(_ row: FMResultSet) -> Author? {
let databaseID = row.string(forColumn: DatabaseKey.databaseID)
if let author = cachedAuthor(databaseID) {
return author
}
guard let author = Author(row: row) else {
return nil
}
cacheAuthor(author)
return author
}
}