mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 09:41:00 +00:00
Rename all "index" columns to "order"
This commit is contained in:
parent
2dae234849
commit
a6cbe6e96d
8 changed files with 19 additions and 17 deletions
|
@ -7,14 +7,14 @@ import Mastodon
|
||||||
struct AccountPinnedStatusJoin: ContentDatabaseRecord {
|
struct AccountPinnedStatusJoin: ContentDatabaseRecord {
|
||||||
let accountId: Account.Id
|
let accountId: Account.Id
|
||||||
let statusId: Status.Id
|
let statusId: Status.Id
|
||||||
let index: Int
|
let order: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
extension AccountPinnedStatusJoin {
|
extension AccountPinnedStatusJoin {
|
||||||
enum Columns {
|
enum Columns {
|
||||||
static let accountId = Column(CodingKeys.accountId)
|
static let accountId = Column(CodingKeys.accountId)
|
||||||
static let statusId = Column(CodingKeys.statusId)
|
static let statusId = Column(CodingKeys.statusId)
|
||||||
static let index = Column(CodingKeys.index)
|
static let order = Column(CodingKeys.order)
|
||||||
}
|
}
|
||||||
|
|
||||||
static let status = belongsTo(StatusRecord.self)
|
static let status = belongsTo(StatusRecord.self)
|
||||||
|
|
|
@ -58,7 +58,7 @@ extension AccountRecord {
|
||||||
static let identityProofs = hasMany(IdentityProofRecord.self)
|
static let identityProofs = hasMany(IdentityProofRecord.self)
|
||||||
static let featuredTags = hasMany(FeaturedTagRecord.self)
|
static let featuredTags = hasMany(FeaturedTagRecord.self)
|
||||||
static let pinnedStatusJoins = hasMany(AccountPinnedStatusJoin.self)
|
static let pinnedStatusJoins = hasMany(AccountPinnedStatusJoin.self)
|
||||||
.order(AccountPinnedStatusJoin.Columns.index)
|
.order(AccountPinnedStatusJoin.Columns.order)
|
||||||
static let pinnedStatuses = hasMany(
|
static let pinnedStatuses = hasMany(
|
||||||
StatusRecord.self,
|
StatusRecord.self,
|
||||||
through: pinnedStatusJoins,
|
through: pinnedStatusJoins,
|
||||||
|
|
|
@ -226,7 +226,7 @@ extension ContentDatabase {
|
||||||
.references("statusRecord", onDelete: .cascade)
|
.references("statusRecord", onDelete: .cascade)
|
||||||
t.column("statusId", .text).indexed().notNull()
|
t.column("statusId", .text).indexed().notNull()
|
||||||
.references("statusRecord", onDelete: .cascade)
|
.references("statusRecord", onDelete: .cascade)
|
||||||
t.column("index", .integer).notNull()
|
t.column("order", .integer).notNull()
|
||||||
|
|
||||||
t.primaryKey(["parentId", "statusId"], onConflict: .replace)
|
t.primaryKey(["parentId", "statusId"], onConflict: .replace)
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ extension ContentDatabase {
|
||||||
.references("statusRecord", onDelete: .cascade)
|
.references("statusRecord", onDelete: .cascade)
|
||||||
t.column("statusId", .text).indexed().notNull()
|
t.column("statusId", .text).indexed().notNull()
|
||||||
.references("statusRecord", onDelete: .cascade)
|
.references("statusRecord", onDelete: .cascade)
|
||||||
t.column("index", .integer).notNull()
|
t.column("order", .integer).notNull()
|
||||||
|
|
||||||
t.primaryKey(["parentId", "statusId"], onConflict: .replace)
|
t.primaryKey(["parentId", "statusId"], onConflict: .replace)
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,7 @@ extension ContentDatabase {
|
||||||
.references("accountRecord", onDelete: .cascade)
|
.references("accountRecord", onDelete: .cascade)
|
||||||
t.column("statusId", .text).indexed().notNull()
|
t.column("statusId", .text).indexed().notNull()
|
||||||
.references("statusRecord", onDelete: .cascade)
|
.references("statusRecord", onDelete: .cascade)
|
||||||
t.column("index", .integer).notNull()
|
t.column("order", .integer).notNull()
|
||||||
|
|
||||||
t.primaryKey(["accountId", "statusId"], onConflict: .replace)
|
t.primaryKey(["accountId", "statusId"], onConflict: .replace)
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,12 +135,12 @@ public extension ContentDatabase {
|
||||||
databaseWriter.writePublisher {
|
databaseWriter.writePublisher {
|
||||||
for (index, status) in context.ancestors.enumerated() {
|
for (index, status) in context.ancestors.enumerated() {
|
||||||
try status.save($0)
|
try status.save($0)
|
||||||
try StatusAncestorJoin(parentId: parentId, statusId: status.id, index: index).save($0)
|
try StatusAncestorJoin(parentId: parentId, statusId: status.id, order: index).save($0)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (index, status) in context.descendants.enumerated() {
|
for (index, status) in context.descendants.enumerated() {
|
||||||
try status.save($0)
|
try status.save($0)
|
||||||
try StatusDescendantJoin(parentId: parentId, statusId: status.id, index: index).save($0)
|
try StatusDescendantJoin(parentId: parentId, statusId: status.id, order: index).save($0)
|
||||||
}
|
}
|
||||||
|
|
||||||
try StatusAncestorJoin.filter(
|
try StatusAncestorJoin.filter(
|
||||||
|
@ -161,7 +161,7 @@ public extension ContentDatabase {
|
||||||
databaseWriter.writePublisher {
|
databaseWriter.writePublisher {
|
||||||
for (index, status) in pinnedStatuses.enumerated() {
|
for (index, status) in pinnedStatuses.enumerated() {
|
||||||
try status.save($0)
|
try status.save($0)
|
||||||
try AccountPinnedStatusJoin(accountId: accountId, statusId: status.id, index: index).save($0)
|
try AccountPinnedStatusJoin(accountId: accountId, statusId: status.id, order: index).save($0)
|
||||||
}
|
}
|
||||||
|
|
||||||
try AccountPinnedStatusJoin.filter(
|
try AccountPinnedStatusJoin.filter(
|
||||||
|
|
|
@ -7,14 +7,14 @@ import Mastodon
|
||||||
struct StatusAncestorJoin: ContentDatabaseRecord {
|
struct StatusAncestorJoin: ContentDatabaseRecord {
|
||||||
let parentId: Status.Id
|
let parentId: Status.Id
|
||||||
let statusId: Status.Id
|
let statusId: Status.Id
|
||||||
let index: Int
|
let order: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
extension StatusAncestorJoin {
|
extension StatusAncestorJoin {
|
||||||
enum Columns {
|
enum Columns {
|
||||||
static let parentId = Column(CodingKeys.parentId)
|
static let parentId = Column(CodingKeys.parentId)
|
||||||
static let statusId = Column(CodingKeys.statusId)
|
static let statusId = Column(CodingKeys.statusId)
|
||||||
static let index = Column(CodingKeys.index)
|
static let order = Column(CodingKeys.order)
|
||||||
}
|
}
|
||||||
|
|
||||||
static let status = belongsTo(StatusRecord.self, using: ForeignKey([Columns.statusId]))
|
static let status = belongsTo(StatusRecord.self, using: ForeignKey([Columns.statusId]))
|
||||||
|
|
|
@ -7,14 +7,14 @@ import Mastodon
|
||||||
struct StatusDescendantJoin: ContentDatabaseRecord {
|
struct StatusDescendantJoin: ContentDatabaseRecord {
|
||||||
let parentId: Status.Id
|
let parentId: Status.Id
|
||||||
let statusId: Status.Id
|
let statusId: Status.Id
|
||||||
let index: Int
|
let order: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
extension StatusDescendantJoin {
|
extension StatusDescendantJoin {
|
||||||
enum Columns {
|
enum Columns {
|
||||||
static let parentId = Column(CodingKeys.parentId)
|
static let parentId = Column(CodingKeys.parentId)
|
||||||
static let statusId = Column(CodingKeys.statusId)
|
static let statusId = Column(CodingKeys.statusId)
|
||||||
static let index = Column(CodingKeys.index)
|
static let order = Column(CodingKeys.order)
|
||||||
}
|
}
|
||||||
|
|
||||||
static let status = belongsTo(StatusRecord.self, using: ForeignKey([Columns.statusId]))
|
static let status = belongsTo(StatusRecord.self, using: ForeignKey([Columns.statusId]))
|
||||||
|
|
|
@ -95,11 +95,11 @@ extension StatusRecord {
|
||||||
static let ancestorJoins = hasMany(
|
static let ancestorJoins = hasMany(
|
||||||
StatusAncestorJoin.self,
|
StatusAncestorJoin.self,
|
||||||
using: ForeignKey([StatusAncestorJoin.Columns.parentId]))
|
using: ForeignKey([StatusAncestorJoin.Columns.parentId]))
|
||||||
.order(StatusAncestorJoin.Columns.index)
|
.order(StatusAncestorJoin.Columns.order)
|
||||||
static let descendantJoins = hasMany(
|
static let descendantJoins = hasMany(
|
||||||
StatusDescendantJoin.self,
|
StatusDescendantJoin.self,
|
||||||
using: ForeignKey([StatusDescendantJoin.Columns.parentId]))
|
using: ForeignKey([StatusDescendantJoin.Columns.parentId]))
|
||||||
.order(StatusDescendantJoin.Columns.index)
|
.order(StatusDescendantJoin.Columns.order)
|
||||||
static let ancestors = hasMany(StatusRecord.self,
|
static let ancestors = hasMany(StatusRecord.self,
|
||||||
through: ancestorJoins,
|
through: ancestorJoins,
|
||||||
using: StatusAncestorJoin.status)
|
using: StatusAncestorJoin.status)
|
||||||
|
|
|
@ -17,7 +17,8 @@ extension TimelineItemsInfo {
|
||||||
let pinnedStatusInfos: [StatusInfo]
|
let pinnedStatusInfos: [StatusInfo]
|
||||||
}
|
}
|
||||||
|
|
||||||
static func addingIncludes<T: DerivableRequest>( _ request: T, ordered: Bool) -> T where T.RowDecoder == TimelineRecord {
|
static func addingIncludes<T: DerivableRequest>( _ request: T,
|
||||||
|
ordered: Bool) -> T where T.RowDecoder == TimelineRecord {
|
||||||
let statusesAssociation = ordered ? TimelineRecord.orderedStatuses : TimelineRecord.statuses
|
let statusesAssociation = ordered ? TimelineRecord.orderedStatuses : TimelineRecord.statuses
|
||||||
|
|
||||||
return request.including(all: StatusInfo.addingIncludes(statusesAssociation).forKey(CodingKeys.statusInfos))
|
return request.including(all: StatusInfo.addingIncludes(statusesAssociation).forKey(CodingKeys.statusInfos))
|
||||||
|
@ -26,7 +27,8 @@ extension TimelineItemsInfo {
|
||||||
.forKey(CodingKeys.pinnedStatusesInfo))
|
.forKey(CodingKeys.pinnedStatusesInfo))
|
||||||
}
|
}
|
||||||
|
|
||||||
static func request(_ request: QueryInterfaceRequest<TimelineRecord>, ordered: Bool) -> QueryInterfaceRequest<Self> {
|
static func request(_ request: QueryInterfaceRequest<TimelineRecord>,
|
||||||
|
ordered: Bool) -> QueryInterfaceRequest<Self> {
|
||||||
addingIncludes(request, ordered: ordered).asRequest(of: self)
|
addingIncludes(request, ordered: ordered).asRequest(of: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue