mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
OrderedRequest.withStableOrder()
This commit is contained in:
1 parent
aadb887b34
commit
7a7ee554c7
14 files changed
+162
No files matched your search
@@ -282,6 +282,21 @@ extension SQLRelation: Refinable {
|
||||
}
|
||||
}
|
||||
|
||||
func withStableOrder() -> Self {
|
||||
with {
|
||||
// Order by primary key. Don't order by rowid because those are
|
||||
// not stable: rowids can change after a vacuum.
|
||||
$0.ordering = $0.ordering.appending(Ordering(orderings: { db in
|
||||
try db.primaryKey(source.tableName).columns.map { SQLExpression.column($0).sqlOrdering }
|
||||
}))
|
||||
$0.children = children.mapValues { child in
|
||||
child.with {
|
||||
$0.relation = $0.relation.withStableOrder()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove ordering iff relation has no LIMIT clause
|
||||
func unorderedUnlessLimited() -> Self {
|
||||
if limit != nil {
|
||||
|
||||
Reference in new issue
Block a user