orderby utilities

This commit is contained in:
John Rommel Estropia
2017-10-02 08:04:28 +09:00
parent 1d2eef7894
commit 06635c9d2f
2 changed files with 68 additions and 0 deletions

View File

@@ -237,6 +237,7 @@ class DynamicModelTests: BaseTestDataTestCase {
_ = transaction.fetchAll(
From<Dog>()
.where(\.age == 10 && \Animal.species == "Dog")
.orderBy(.ascending({ $0.species }))
)
_ = transaction.fetchAll(
From<Dog>(),

View File

@@ -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