mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 08:10:59 +00:00
Refactoring
This commit is contained in:
parent
cc370af881
commit
66e7b01282
15 changed files with 33 additions and 83 deletions
|
@ -3,7 +3,7 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
|
|
||||||
public struct AccountList: Codable, FetchableRecord, PersistableRecord {
|
public struct AccountList: ContentDatabaseRecord {
|
||||||
let id: Id
|
let id: Id
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
import Mastodon
|
import Mastodon
|
||||||
|
|
||||||
struct AccountListJoin: Codable, FetchableRecord, PersistableRecord {
|
struct AccountListJoin: ContentDatabaseRecord {
|
||||||
let accountId: Account.Id
|
let accountId: Account.Id
|
||||||
let listId: AccountList.Id
|
let listId: AccountList.Id
|
||||||
let index: Int
|
let index: Int
|
||||||
|
|
|
@ -4,7 +4,7 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
import Mastodon
|
import Mastodon
|
||||||
|
|
||||||
struct AccountPinnedStatusJoin: Codable, FetchableRecord, PersistableRecord {
|
struct AccountPinnedStatusJoin: ContentDatabaseRecord {
|
||||||
let accountId: Account.Id
|
let accountId: Account.Id
|
||||||
let statusId: Status.Id
|
let statusId: Status.Id
|
||||||
let index: Int
|
let index: Int
|
||||||
|
|
|
@ -4,7 +4,7 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
import Mastodon
|
import Mastodon
|
||||||
|
|
||||||
struct AccountRecord: Codable, Hashable {
|
struct AccountRecord: ContentDatabaseRecord, Hashable {
|
||||||
let id: Account.Id
|
let id: Account.Id
|
||||||
let username: String
|
let username: String
|
||||||
let acct: 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 {
|
extension AccountRecord {
|
||||||
static let moved = belongsTo(AccountRecord.self)
|
static let moved = belongsTo(AccountRecord.self)
|
||||||
static let pinnedStatusJoins = hasMany(AccountPinnedStatusJoin.self)
|
static let pinnedStatusJoins = hasMany(AccountPinnedStatusJoin.self)
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
// Copyright © 2020 Metabolist. All rights reserved.
|
// Copyright © 2020 Metabolist. All rights reserved.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import Mastodon
|
||||||
|
|
||||||
public final class MastodonEncoder: JSONEncoder {
|
final class ContentDatabaseJSONEncoder: JSONEncoder {
|
||||||
public override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
let dateFormatter = DateFormatter()
|
let dateFormatter = DateFormatter()
|
17
DB/Sources/DB/Content/ContentDatabaseRecord.swift
Normal file
17
DB/Sources/DB/Content/ContentDatabaseRecord.swift
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
import Mastodon
|
import Mastodon
|
||||||
|
|
||||||
struct LoadMoreRecord: Codable, Hashable {
|
struct LoadMoreRecord: ContentDatabaseRecord, Hashable {
|
||||||
let timelineId: Timeline.Id
|
let timelineId: Timeline.Id
|
||||||
let afterStatusId: Status.Id
|
let afterStatusId: Status.Id
|
||||||
let beforeStatusId: Status.Id
|
let beforeStatusId: Status.Id
|
||||||
|
@ -17,13 +17,3 @@ extension LoadMoreRecord {
|
||||||
static let beforeStatusId = Column(LoadMoreRecord.CodingKeys.beforeStatusId)
|
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
import Mastodon
|
import Mastodon
|
||||||
|
|
||||||
struct StatusAncestorJoin: Codable, FetchableRecord, PersistableRecord {
|
struct StatusAncestorJoin: ContentDatabaseRecord {
|
||||||
let parentId: Status.Id
|
let parentId: Status.Id
|
||||||
let statusId: Status.Id
|
let statusId: Status.Id
|
||||||
let index: Int
|
let index: Int
|
||||||
|
|
|
@ -4,7 +4,7 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
import Mastodon
|
import Mastodon
|
||||||
|
|
||||||
struct StatusDescendantJoin: Codable, FetchableRecord, PersistableRecord {
|
struct StatusDescendantJoin: ContentDatabaseRecord {
|
||||||
let parentId: Status.Id
|
let parentId: Status.Id
|
||||||
let statusId: Status.Id
|
let statusId: Status.Id
|
||||||
let index: Int
|
let index: Int
|
||||||
|
|
|
@ -4,7 +4,7 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
import Mastodon
|
import Mastodon
|
||||||
|
|
||||||
struct StatusRecord: Codable, Hashable {
|
struct StatusRecord: ContentDatabaseRecord, Hashable {
|
||||||
let id: Status.Id
|
let id: Status.Id
|
||||||
let uri: String
|
let uri: String
|
||||||
let createdAt: Date
|
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 {
|
extension StatusRecord {
|
||||||
static let account = belongsTo(AccountRecord.self)
|
static let account = belongsTo(AccountRecord.self)
|
||||||
static let accountMoved = hasOne(AccountRecord.self,
|
static let accountMoved = hasOne(AccountRecord.self,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
import Mastodon
|
import Mastodon
|
||||||
|
|
||||||
struct StatusShowAttachmentsToggle: Codable, Hashable {
|
struct StatusShowAttachmentsToggle: ContentDatabaseRecord, Hashable {
|
||||||
let statusId: Status.Id
|
let statusId: Status.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,13 +13,3 @@ extension StatusShowAttachmentsToggle {
|
||||||
static let statusId = Column(StatusShowAttachmentsToggle.CodingKeys.statusId)
|
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
import Mastodon
|
import Mastodon
|
||||||
|
|
||||||
struct StatusShowContentToggle: Codable, Hashable {
|
struct StatusShowContentToggle: ContentDatabaseRecord, Hashable {
|
||||||
let statusId: Status.Id
|
let statusId: Status.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,13 +13,3 @@ extension StatusShowContentToggle {
|
||||||
static let statusId = Column(StatusShowContentToggle.CodingKeys.statusId)
|
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
import Mastodon
|
import Mastodon
|
||||||
|
|
||||||
struct TimelineRecord: Codable, Hashable {
|
struct TimelineRecord: ContentDatabaseRecord, Hashable {
|
||||||
let id: Timeline.Id
|
let id: Timeline.Id
|
||||||
let listId: List.Id?
|
let listId: List.Id?
|
||||||
let listTitle: String?
|
let listTitle: String?
|
||||||
|
@ -13,16 +13,6 @@ struct TimelineRecord: Codable, Hashable {
|
||||||
let profileCollection: ProfileCollection?
|
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 {
|
extension TimelineRecord {
|
||||||
enum Columns {
|
enum Columns {
|
||||||
static let id = Column(TimelineRecord.CodingKeys.id)
|
static let id = Column(TimelineRecord.CodingKeys.id)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
import Mastodon
|
import Mastodon
|
||||||
|
|
||||||
struct TimelineStatusJoin: Codable, FetchableRecord, PersistableRecord {
|
struct TimelineStatusJoin: ContentDatabaseRecord {
|
||||||
let timelineId: Timeline.Id
|
let timelineId: Timeline.Id
|
||||||
let statusId: Status.Id
|
let statusId: Status.Id
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,7 @@ import Foundation
|
||||||
import GRDB
|
import GRDB
|
||||||
import Mastodon
|
import Mastodon
|
||||||
|
|
||||||
extension Filter: FetchableRecord, PersistableRecord {
|
extension Filter: ContentDatabaseRecord {}
|
||||||
public static func databaseJSONDecoder(for column: String) -> JSONDecoder {
|
|
||||||
MastodonDecoder()
|
|
||||||
}
|
|
||||||
|
|
||||||
public static func databaseJSONEncoder(for column: String) -> JSONEncoder {
|
|
||||||
MastodonEncoder()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Filter {
|
extension Filter {
|
||||||
enum Columns: String, ColumnExpression {
|
enum Columns: String, ColumnExpression {
|
||||||
|
|
Loading…
Reference in a new issue