NetNewsWire/Frameworks/ArticlesDatabase/AuthorsTable.swift

40 lines
980 B
Swift
Raw Normal View History

2017-07-13 22:38:47 +02:00
//
// AuthorsTable.swift
// NetNewsWire
2017-07-13 22:38:47 +02:00
//
// Created by Brent Simmons on 7/13/17.
// Copyright © 2017 Ranchero Software. All rights reserved.
//
import Foundation
2017-08-04 06:10:01 +02:00
import RSDatabase
import Articles
2017-07-13 22:38:47 +02:00
2017-08-06 21:37:47 +02:00
// article->authors is a many-to-many relationship.
// Theres a lookup table relating authorID and articleID.
//
// CREATE TABLE if not EXISTS authors (authorID TEXT NOT NULL PRIMARY KEY, name TEXT, url TEXT, avatarURL TEXT, emailAddress TEXT);
2017-08-06 21:37:47 +02:00
// CREATE TABLE if not EXISTS authorLookup (authorID TEXT NOT NULL, articleID TEXT NOT NULL, PRIMARY KEY(authorID, articleID));
final class AuthorsTable: DatabaseRelatedObjectsTable {
2017-08-21 00:56:58 +02:00
let name: String
let databaseIDKey = DatabaseKey.authorID
2017-09-13 07:06:59 +02:00
var cache = DatabaseObjectCache()
2017-08-21 00:56:58 +02:00
init(name: String) {
self.name = name
}
2017-08-21 00:56:58 +02:00
// MARK: - DatabaseRelatedObjectsTable
func objectWithRow(_ row: FMResultSet) -> DatabaseObject? {
2017-09-14 02:40:25 +02:00
if let author = Author(row: row) {
return author as DatabaseObject
}
return nil
2017-08-21 00:56:58 +02:00
}
2017-08-06 21:37:47 +02:00
}