mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-04-01 07:03:06 +02:00
orderby utilities
This commit is contained in:
@@ -237,6 +237,7 @@ class DynamicModelTests: BaseTestDataTestCase {
|
|||||||
_ = transaction.fetchAll(
|
_ = transaction.fetchAll(
|
||||||
From<Dog>()
|
From<Dog>()
|
||||||
.where(\.age == 10 && \Animal.species == "Dog")
|
.where(\.age == 10 && \Animal.species == "Dog")
|
||||||
|
.orderBy(.ascending({ $0.species }))
|
||||||
)
|
)
|
||||||
_ = transaction.fetchAll(
|
_ = transaction.fetchAll(
|
||||||
From<Dog>(),
|
From<Dog>(),
|
||||||
|
|||||||
@@ -257,6 +257,73 @@ public struct OrderBy<D: DynamicObject>: OrderByClause, FetchClause, QueryClause
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public extension OrderBy where D: CoreStoreObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
Indicates that the `KeyPathString` should be sorted in ascending order
|
||||||
|
*/
|
||||||
|
public static func ascending<DSub, A, T>(_ attribute: (D) -> A) -> SortKey where A: ValueContainer<DSub>.Required<T> {
|
||||||
|
|
||||||
|
return .ascending(attribute(D.meta).keyPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Indicates that the `KeyPathString` should be sorted in ascending order
|
||||||
|
*/
|
||||||
|
public static func ascending<DSub, A, T>(_ attribute: (D) -> A) -> SortKey where A: ValueContainer<DSub>.Optional<T> {
|
||||||
|
|
||||||
|
return .ascending(attribute(D.meta).keyPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Indicates that the `KeyPathString` should be sorted in ascending order
|
||||||
|
*/
|
||||||
|
public static func ascending<DSub, A, T>(_ attribute: (D) -> A) -> SortKey where A: TransformableContainer<DSub>.Required<T> {
|
||||||
|
|
||||||
|
return .ascending(attribute(D.meta).keyPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Indicates that the `KeyPathString` should be sorted in ascending order
|
||||||
|
*/
|
||||||
|
public static func ascending<DSub, A, T>(_ attribute: (D) -> A) -> SortKey where A: TransformableContainer<DSub>.Optional<T> {
|
||||||
|
|
||||||
|
return .ascending(attribute(D.meta).keyPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Indicates that the `KeyPathString` should be sorted in descending order
|
||||||
|
*/
|
||||||
|
public static func descending<DSub, A, T>(_ attribute: (D) -> A) -> SortKey where A: ValueContainer<DSub>.Required<T> {
|
||||||
|
|
||||||
|
return .descending(attribute(D.meta).keyPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Indicates that the `KeyPathString` should be sorted in descending order
|
||||||
|
*/
|
||||||
|
public static func descending<DSub, A, T>(_ attribute: (D) -> A) -> SortKey where A: ValueContainer<DSub>.Optional<T> {
|
||||||
|
|
||||||
|
return .descending(attribute(D.meta).keyPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Indicates that the `KeyPathString` should be sorted in descending order
|
||||||
|
*/
|
||||||
|
public static func descending<DSub, A, T>(_ attribute: (D) -> A) -> SortKey where A: TransformableContainer<DSub>.Required<T> {
|
||||||
|
|
||||||
|
return .descending(attribute(D.meta).keyPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Indicates that the `KeyPathString` should be sorted in descending order
|
||||||
|
*/
|
||||||
|
public static func descending<DSub, A, T>(_ attribute: (D) -> A) -> SortKey where A: TransformableContainer<DSub>.Optional<T> {
|
||||||
|
|
||||||
|
return .descending(attribute(D.meta).keyPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - OrderByClause
|
// MARK: - OrderByClause
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user