mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-30 04:28:44 +00:00
The stable order for views is provided by the schemaSource, if any
This commit is contained in:
1 parent
26ebd7e147
commit
93d0baeade
1 file changed
+6
-3
@@ -285,12 +285,15 @@ extension SQLRelation: Refinable {
|
||||
func withStableOrder() -> Self {
|
||||
with { relation in
|
||||
relation.ordering = relation.ordering.appending(Ordering(orderings: { [relation] db in
|
||||
if try db.tableExists(source.tableName) {
|
||||
do {
|
||||
#warning("TODO: test with views")
|
||||
// Order by primary key. Don't order by rowid because those are
|
||||
// not stable: rowids can change after a vacuum.
|
||||
return try db.primaryKey(source.tableName).columns.map { SQLExpression.column($0).sqlOrdering }
|
||||
} else {
|
||||
// Support for views: create a stable order from all columns:
|
||||
} catch {
|
||||
// Could not find the primary key. Assume we're ordering
|
||||
// a view that is not customized with the schemaSource.
|
||||
// Create a stable order from all columns:
|
||||
// ORDER BY 1, 2, 3, ...
|
||||
let columnCount = try SQLQueryGenerator(relation: relation).columnCount(db)
|
||||
return (1...columnCount).map { SQL(sql: $0.description).sqlOrdering }
|
||||
|
||||
Reference in new issue
Block a user