Refactoring

This commit is contained in:
Justin Mazzocchi 2020-10-13 17:28:27 -07:00
parent cc370af881
commit 66e7b01282
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
15 changed files with 33 additions and 83 deletions

View file

@ -3,7 +3,7 @@
import Foundation
import GRDB
public struct AccountList: Codable, FetchableRecord, PersistableRecord {
public struct AccountList: ContentDatabaseRecord {
let id: Id
public init() {

View file

@ -4,7 +4,7 @@ import Foundation
import GRDB
import Mastodon
struct AccountListJoin: Codable, FetchableRecord, PersistableRecord {
struct AccountListJoin: ContentDatabaseRecord {
let accountId: Account.Id
let listId: AccountList.Id
let index: Int

View file

@ -4,7 +4,7 @@ import Foundation
import GRDB
import Mastodon
struct AccountPinnedStatusJoin: Codable, FetchableRecord, PersistableRecord {
struct AccountPinnedStatusJoin: ContentDatabaseRecord {
let accountId: Account.Id
let statusId: Status.Id
let index: Int

View file

@ -4,7 +4,7 @@ import Foundation
import GRDB
import Mastodon
struct AccountRecord: Codable, Hashable {
struct AccountRecord: ContentDatabaseRecord, Hashable {
let id: Account.Id
let username: String
let acct: String
@ -52,16 +52,6 @@ extension AccountRecord {
}
}
extension AccountRecord: FetchableRecord, PersistableRecord {
static func databaseJSONDecoder(for column: String) -> JSONDecoder {
MastodonDecoder()
}
static func databaseJSONEncoder(for column: String) -> JSONEncoder {
MastodonEncoder()
}
}
extension AccountRecord {
static let moved = belongsTo(AccountRecord.self)
static let pinnedStatusJoins = hasMany(AccountPinnedStatusJoin.self)

View file

@ -1,9 +1,10 @@
// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
import Mastodon
public final class MastodonEncoder: JSONEncoder {
public override init() {
final class ContentDatabaseJSONEncoder: JSONEncoder {
override init() {
super.init()
let dateFormatter = DateFormatter()

View file

@ -0,0 +1,17 @@
// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
import GRDB
import Mastodon
protocol ContentDatabaseRecord: Codable, FetchableRecord, PersistableRecord {}
extension ContentDatabaseRecord {
public static func databaseJSONDecoder(for column: String) -> JSONDecoder {
MastodonDecoder()
}
public static func databaseJSONEncoder(for column: String) -> JSONEncoder {
ContentDatabaseJSONEncoder()
}
}

View file

@ -4,7 +4,7 @@ import Foundation
import GRDB
import Mastodon
struct LoadMoreRecord: Codable, Hashable {
struct LoadMoreRecord: ContentDatabaseRecord, Hashable {
let timelineId: Timeline.Id
let afterStatusId: Status.Id
let beforeStatusId: Status.Id
@ -17,13 +17,3 @@ extension LoadMoreRecord {
static let beforeStatusId = Column(LoadMoreRecord.CodingKeys.beforeStatusId)
}
}
extension LoadMoreRecord: FetchableRecord, PersistableRecord {
static func databaseJSONDecoder(for column: String) -> JSONDecoder {
MastodonDecoder()
}
static func databaseJSONEncoder(for column: String) -> JSONEncoder {
MastodonEncoder()
}
}

View file

@ -4,7 +4,7 @@ import Foundation
import GRDB
import Mastodon
struct StatusAncestorJoin: Codable, FetchableRecord, PersistableRecord {
struct StatusAncestorJoin: ContentDatabaseRecord {
let parentId: Status.Id
let statusId: Status.Id
let index: Int

View file

@ -4,7 +4,7 @@ import Foundation
import GRDB
import Mastodon
struct StatusDescendantJoin: Codable, FetchableRecord, PersistableRecord {
struct StatusDescendantJoin: ContentDatabaseRecord {
let parentId: Status.Id
let statusId: Status.Id
let index: Int

View file

@ -4,7 +4,7 @@ import Foundation
import GRDB
import Mastodon
struct StatusRecord: Codable, Hashable {
struct StatusRecord: ContentDatabaseRecord, Hashable {
let id: Status.Id
let uri: String
let createdAt: Date
@ -70,16 +70,6 @@ extension StatusRecord {
}
}
extension StatusRecord: FetchableRecord, PersistableRecord {
static func databaseJSONDecoder(for column: String) -> JSONDecoder {
MastodonDecoder()
}
static func databaseJSONEncoder(for column: String) -> JSONEncoder {
MastodonEncoder()
}
}
extension StatusRecord {
static let account = belongsTo(AccountRecord.self)
static let accountMoved = hasOne(AccountRecord.self,

View file

@ -4,7 +4,7 @@ import Foundation
import GRDB
import Mastodon
struct StatusShowAttachmentsToggle: Codable, Hashable {
struct StatusShowAttachmentsToggle: ContentDatabaseRecord, Hashable {
let statusId: Status.Id
}
@ -13,13 +13,3 @@ extension StatusShowAttachmentsToggle {
static let statusId = Column(StatusShowAttachmentsToggle.CodingKeys.statusId)
}
}
extension StatusShowAttachmentsToggle: FetchableRecord, PersistableRecord {
static func databaseJSONDecoder(for column: String) -> JSONDecoder {
MastodonDecoder()
}
static func databaseJSONEncoder(for column: String) -> JSONEncoder {
MastodonEncoder()
}
}

View file

@ -4,7 +4,7 @@ import Foundation
import GRDB
import Mastodon
struct StatusShowContentToggle: Codable, Hashable {
struct StatusShowContentToggle: ContentDatabaseRecord, Hashable {
let statusId: Status.Id
}
@ -13,13 +13,3 @@ extension StatusShowContentToggle {
static let statusId = Column(StatusShowContentToggle.CodingKeys.statusId)
}
}
extension StatusShowContentToggle: FetchableRecord, PersistableRecord {
static func databaseJSONDecoder(for column: String) -> JSONDecoder {
MastodonDecoder()
}
static func databaseJSONEncoder(for column: String) -> JSONEncoder {
MastodonEncoder()
}
}

View file

@ -4,7 +4,7 @@ import Foundation
import GRDB
import Mastodon
struct TimelineRecord: Codable, Hashable {
struct TimelineRecord: ContentDatabaseRecord, Hashable {
let id: Timeline.Id
let listId: List.Id?
let listTitle: String?
@ -13,16 +13,6 @@ struct TimelineRecord: Codable, Hashable {
let profileCollection: ProfileCollection?
}
extension TimelineRecord: FetchableRecord, PersistableRecord {
static func databaseJSONDecoder(for column: String) -> JSONDecoder {
MastodonDecoder()
}
static func databaseJSONEncoder(for column: String) -> JSONEncoder {
MastodonEncoder()
}
}
extension TimelineRecord {
enum Columns {
static let id = Column(TimelineRecord.CodingKeys.id)

View file

@ -4,7 +4,7 @@ import Foundation
import GRDB
import Mastodon
struct TimelineStatusJoin: Codable, FetchableRecord, PersistableRecord {
struct TimelineStatusJoin: ContentDatabaseRecord {
let timelineId: Timeline.Id
let statusId: Status.Id

View file

@ -4,15 +4,7 @@ import Foundation
import GRDB
import Mastodon
extension Filter: FetchableRecord, PersistableRecord {
public static func databaseJSONDecoder(for column: String) -> JSONDecoder {
MastodonDecoder()
}
public static func databaseJSONEncoder(for column: String) -> JSONEncoder {
MastodonEncoder()
}
}
extension Filter: ContentDatabaseRecord {}
extension Filter {
enum Columns: String, ColumnExpression {