diff --git a/CoreStoreTests/DynamicModelTests.swift b/CoreStoreTests/DynamicModelTests.swift index 30e97cd..4d68ddb 100644 --- a/CoreStoreTests/DynamicModelTests.swift +++ b/CoreStoreTests/DynamicModelTests.swift @@ -237,6 +237,7 @@ class DynamicModelTests: BaseTestDataTestCase { _ = transaction.fetchAll( From() .where(\.age == 10 && \Animal.species == "Dog") + .orderBy(.ascending({ $0.species })) ) _ = transaction.fetchAll( From(), diff --git a/Sources/OrderBy.swift b/Sources/OrderBy.swift index f5199c4..247b66a 100644 --- a/Sources/OrderBy.swift +++ b/Sources/OrderBy.swift @@ -257,6 +257,73 @@ public struct OrderBy: OrderByClause, FetchClause, QueryClause } } +public extension OrderBy where D: CoreStoreObject { + + /** + Indicates that the `KeyPathString` should be sorted in ascending order + */ + public static func ascending(_ attribute: (D) -> A) -> SortKey where A: ValueContainer.Required { + + return .ascending(attribute(D.meta).keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in ascending order + */ + public static func ascending(_ attribute: (D) -> A) -> SortKey where A: ValueContainer.Optional { + + return .ascending(attribute(D.meta).keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in ascending order + */ + public static func ascending(_ attribute: (D) -> A) -> SortKey where A: TransformableContainer.Required { + + return .ascending(attribute(D.meta).keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in ascending order + */ + public static func ascending(_ attribute: (D) -> A) -> SortKey where A: TransformableContainer.Optional { + + return .ascending(attribute(D.meta).keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in descending order + */ + public static func descending(_ attribute: (D) -> A) -> SortKey where A: ValueContainer.Required { + + return .descending(attribute(D.meta).keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in descending order + */ + public static func descending(_ attribute: (D) -> A) -> SortKey where A: ValueContainer.Optional { + + return .descending(attribute(D.meta).keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in descending order + */ + public static func descending(_ attribute: (D) -> A) -> SortKey where A: TransformableContainer.Required { + + return .descending(attribute(D.meta).keyPath) + } + + /** + Indicates that the `KeyPathString` should be sorted in descending order + */ + public static func descending(_ attribute: (D) -> A) -> SortKey where A: TransformableContainer.Optional { + + return .descending(attribute(D.meta).keyPath) + } +} + // MARK: - OrderByClause