Merge branch 'prototype/queryBuilders' of github.com:JohnEstropia/CoreStore into prototype/queryBuilders

This commit is contained in:
John Rommel Estropia
2017-09-20 00:02:36 +09:00
5 changed files with 41 additions and 21 deletions

View File

@@ -2627,6 +2627,7 @@
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 9.0; TVOS_DEPLOYMENT_TARGET = 9.0;
VERSIONING_SYSTEM = "apple-generic"; VERSIONING_SYSTEM = "apple-generic";
@@ -2680,6 +2681,7 @@
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 9.0; TVOS_DEPLOYMENT_TARGET = 9.0;
VALIDATE_PRODUCT = YES; VALIDATE_PRODUCT = YES;
@@ -2955,7 +2957,7 @@
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 3.0; SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 4; TARGETED_DEVICE_FAMILY = 4;
}; };
name = Debug; name = Debug;
@@ -2979,7 +2981,7 @@
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-O"; SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 3.0; SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 4; TARGETED_DEVICE_FAMILY = 4;
}; };
name = Release; name = Release;

View File

@@ -408,6 +408,7 @@
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
}; };
name = Debug; name = Debug;
}; };
@@ -447,6 +448,7 @@
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_SWIFT3_OBJC_INFERENCE = Off; SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
VALIDATE_PRODUCT = YES; VALIDATE_PRODUCT = YES;
}; };
name = Release; name = Release;

View File

@@ -230,15 +230,15 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
) )
] ]
private let queryingItems = [ private let queryingItems: [(title: String, query: () -> Any)] = [
( (
title: "Number of Time Zones", title: "Number of Time Zones",
query: { () -> Any in query: { () -> Any in
return Static.timeZonesStack.queryValue( return Static.timeZonesStack.queryValue(
From<TimeZone>(), From<TimeZone>()
Select<NSNumber>(.count(#keyPath(TimeZone.name))) .select(NSNumber.self, .count(#keyPath(TimeZone.name)))
)! )! as Any
} }
), ),
( (
@@ -246,10 +246,10 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
query: { () -> Any in query: { () -> Any in
return Static.timeZonesStack.queryValue( return Static.timeZonesStack.queryValue(
From<TimeZone>(), From<TimeZone>()
Select<String>(#keyPath(TimeZone.abbreviation)), .select(String.self, .attribute(#keyPath(TimeZone.abbreviation)))
Where("%K ENDSWITH[c] %@", #keyPath(TimeZone.name), "Tokyo") .where(format: "%K ENDSWITH[c] %@", #keyPath(TimeZone.name), "Tokyo")
)! )! as Any
} }
), ),
( (
@@ -257,9 +257,13 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
query: { () -> Any in query: { () -> Any in
return Static.timeZonesStack.queryAttributes( return Static.timeZonesStack.queryAttributes(
From<TimeZone>(), From<TimeZone>()
Select<NSDictionary>(#keyPath(TimeZone.name), #keyPath(TimeZone.abbreviation)), .select(
OrderBy(.ascending(#keyPath(TimeZone.name))) NSDictionary.self,
.attribute(#keyPath(TimeZone.name)),
.attribute(#keyPath(TimeZone.abbreviation))
)
.orderBy(.ascending(#keyPath(TimeZone.name)))
)! )!
} }
), ),
@@ -268,10 +272,17 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
query: { () -> Any in query: { () -> Any in
return Static.timeZonesStack.queryAttributes( return Static.timeZonesStack.queryAttributes(
From<TimeZone>(), From<TimeZone>()
Select<NSDictionary>(.count(#keyPath(TimeZone.abbreviation)), #keyPath(TimeZone.abbreviation)), .select(
GroupBy(#keyPath(TimeZone.abbreviation)), NSDictionary.self,
OrderBy(.ascending(#keyPath(TimeZone.secondsFromGMT)), .ascending(#keyPath(TimeZone.name))) .count(#keyPath(TimeZone.abbreviation)),
.attribute(#keyPath(TimeZone.abbreviation))
)
.groupBy(#keyPath(TimeZone.abbreviation))
.orderBy(
.ascending(#keyPath(TimeZone.secondsFromGMT)),
.ascending(#keyPath(TimeZone.name))
)
)! )!
} }
), ),
@@ -285,8 +296,8 @@ class FetchingAndQueryingDemoViewController: UIViewController, UITableViewDataSo
.count(#keyPath(TimeZone.hasDaylightSavingTime), as: "numberOfCountries"), .count(#keyPath(TimeZone.hasDaylightSavingTime), as: "numberOfCountries"),
#keyPath(TimeZone.hasDaylightSavingTime) #keyPath(TimeZone.hasDaylightSavingTime)
), ),
GroupBy(#keyPath(TimeZone.hasDaylightSavingTime)), GroupBy<TimeZone>(#keyPath(TimeZone.hasDaylightSavingTime)),
OrderBy(.descending(#keyPath(TimeZone.hasDaylightSavingTime))) OrderBy<TimeZone>(.descending(#keyPath(TimeZone.hasDaylightSavingTime)))
)! )!
} }
) )

View File

@@ -370,8 +370,8 @@ class MigrationsDemoViewController: UIViewController, ListObserver, UITableViewD
self._dataStack = dataStack self._dataStack = dataStack
let listMonitor = dataStack.monitorList( let listMonitor = dataStack.monitorList(
From(model.entityType) From(model.entityType),
.orderBy(.descending(#keyPath(OrganismV1.dna))) OrderBy<NSManagedObject>(.descending(#keyPath(OrganismV1.dna)))
) )
listMonitor.addObserver(self) listMonitor.addObserver(self)
self._listMonitor = listMonitor self._listMonitor = listMonitor

View File

@@ -45,6 +45,7 @@ public protocol QueryChainableBuilderType {
var queryClauses: [QueryClause] { get set } var queryClauses: [QueryClause] { get set }
} }
@available(OSX 10.12, *)
public protocol SectionMonitorBuilderType { public protocol SectionMonitorBuilderType {
associatedtype ObjectType: DynamicObject associatedtype ObjectType: DynamicObject
@@ -85,6 +86,7 @@ public struct QueryChainBuilder<D: DynamicObject, R: SelectResultType>: QueryCha
// MARK: - SectionMonitorChainBuilder // MARK: - SectionMonitorChainBuilder
@available(OSX 10.12, *)
public struct SectionMonitorChainBuilder<D: DynamicObject>: SectionMonitorBuilderType { public struct SectionMonitorChainBuilder<D: DynamicObject>: SectionMonitorBuilderType {
// MARK: SectionMonitorBuilderType // MARK: SectionMonitorBuilderType
@@ -113,11 +115,13 @@ public extension From {
) )
} }
@available(OSX 10.12, *)
public func sectionBy(_ sectionKeyPath: KeyPathString) -> SectionMonitorChainBuilder<D> { public func sectionBy(_ sectionKeyPath: KeyPathString) -> SectionMonitorChainBuilder<D> {
return self.sectionBy(sectionKeyPath, { $0 }) return self.sectionBy(sectionKeyPath, { $0 })
} }
@available(OSX 10.12, *)
public func sectionBy(_ sectionKeyPath: KeyPathString, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> SectionMonitorChainBuilder<D> { public func sectionBy(_ sectionKeyPath: KeyPathString, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> SectionMonitorChainBuilder<D> {
return .init( return .init(
@@ -270,6 +274,7 @@ public extension QueryChainBuilder {
} }
} }
@available(OSX 10.12, *)
public extension SectionMonitorChainBuilder { public extension SectionMonitorChainBuilder {
public func `where`(_ clause: Where<D>) -> SectionMonitorChainBuilder<D> { public func `where`(_ clause: Where<D>) -> SectionMonitorChainBuilder<D> {