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