Fix some build errors.

This commit is contained in:
Brent Simmons 2017-09-13 17:40:25 -07:00
parent 302cda90ba
commit 57cf5a25d7
4 changed files with 32 additions and 45 deletions

View File

@ -32,27 +32,10 @@ final class AuthorsTable: DatabaseRelatedObjectsTable {
func objectWithRow(_ row: FMResultSet) -> DatabaseObject? {
if let author = Author.authorWithRow(row) {
if let author = Author(row: row) {
return author as DatabaseObject
}
return nil
}
func save(_ objects: [DatabaseObject], in database: FMDatabase) {
let attachments = objects.map { $0 as! Author }
// Authors in cache must already exist in database. Filter them out.
let authorsToSave = Set(attachments.filter { (attachment) -> Bool in
if let _ = cache[attachment.attachmentID] {
return false
}
return true
})
cacheAttachments(attachmentsToSave)
insertRows(attachmentsToSave.databaseDictionaries(), insertType: .orIgnore, in: database)
}
}

View File

@ -61,7 +61,7 @@ extension Attachment: DatabaseObject {
}
}
func databaseDictionary() -> NSDictionary? {
public func databaseDictionary() -> NSDictionary? {
let d = NSMutableDictionary()

View File

@ -13,34 +13,10 @@ import RSParser
// MARK: - DatabaseObject
extension Author: DatabaseObject {
public func databaseDictionary() -> NSDictionary? {
var d = NSMutableDictionary()
// TODO
if d.count < 1 {
return nil
}
return (d.copy() as! NSDictionary)
}
public var databaseID: String {
get {
return authorID
}
}
}
// MARK: - Private
private extension Author {
extension Author {
init?(row: FMResultSet) {
let authorID = row.string(forColumn: DatabaseKey.authorID)
let name = row.string(forColumn: DatabaseKey.name)
let url = row.string(forColumn: DatabaseKey.url)
@ -56,6 +32,27 @@ private extension Author {
}
}
extension Author: DatabaseObject {
public var databaseID: String {
get {
return authorID
}
}
public func databaseDictionary() -> NSDictionary? {
var d = NSMutableDictionary()
// TODO
if d.count < 1 {
return nil
}
return (d.copy() as! NSDictionary)
}
}
// MARK: Author creation from Set<ParsedAuthor>
extension Set where Element == ParsedAuthor {

View File

@ -14,6 +14,13 @@ import RSDatabase
extension String: DatabaseObject {
public func databaseDictionary() -> NSDictionary? {
preconditionFailure("databaseDictionary() called for a tag: this should never happen.")
return nil // unused
}
public var databaseID: String {
get {
return self