keyPath utilities for Select queries

This commit is contained in:
John Rommel Estropia
2017-09-21 07:56:02 +09:00
parent 3e082d5ed4
commit 1bfb7451c3
12 changed files with 938 additions and 261 deletions

View File

@@ -49,7 +49,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Bool>(#keyPath(TestEntity1.testBoolean)), Select<TestEntity1, Bool>(#keyPath(TestEntity1.testBoolean)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -59,7 +59,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int8>(#keyPath(TestEntity1.testNumber)), Select<TestEntity1, Int8>(#keyPath(TestEntity1.testNumber)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -69,7 +69,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int16>(#keyPath(TestEntity1.testNumber)), Select<TestEntity1, Int16>(#keyPath(TestEntity1.testNumber)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -79,7 +79,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int32>(#keyPath(TestEntity1.testNumber)), Select<TestEntity1, Int32>(#keyPath(TestEntity1.testNumber)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -89,7 +89,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int64>(#keyPath(TestEntity1.testNumber)), Select<TestEntity1, Int64>(#keyPath(TestEntity1.testNumber)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -99,7 +99,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int>(#keyPath(TestEntity1.testNumber)), Select<TestEntity1, Int>(#keyPath(TestEntity1.testNumber)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -109,7 +109,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Double>(#keyPath(TestEntity1.testNumber)), Select<TestEntity1, Double>(#keyPath(TestEntity1.testNumber)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -119,7 +119,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Float>(#keyPath(TestEntity1.testNumber)), Select<TestEntity1, Float>(#keyPath(TestEntity1.testNumber)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -129,7 +129,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSNumber>(#keyPath(TestEntity1.testNumber)), Select<TestEntity1, NSNumber>(#keyPath(TestEntity1.testNumber)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -139,7 +139,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDecimalNumber>(#keyPath(TestEntity1.testDecimal)), Select<TestEntity1, NSDecimalNumber>(#keyPath(TestEntity1.testDecimal)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -149,7 +149,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<String>(#keyPath(TestEntity1.testString)), Select<TestEntity1, String>(#keyPath(TestEntity1.testString)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -159,7 +159,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSString>(#keyPath(TestEntity1.testString)), Select<TestEntity1, NSString>(#keyPath(TestEntity1.testString)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -169,7 +169,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Data>(#keyPath(TestEntity1.testData)), Select<TestEntity1, Data>(#keyPath(TestEntity1.testData)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -179,7 +179,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSData>(#keyPath(TestEntity1.testData)), Select<TestEntity1, NSData>(#keyPath(TestEntity1.testData)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -189,7 +189,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Date>(#keyPath(TestEntity1.testDate)), Select<TestEntity1, Date>(#keyPath(TestEntity1.testDate)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -199,7 +199,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDate>(#keyPath(TestEntity1.testDate)), Select<TestEntity1, NSDate>(#keyPath(TestEntity1.testDate)),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -209,7 +209,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSManagedObjectID>(#keyPath(TestEntity1.testDate)), Select<TestEntity1, NSManagedObjectID>(#keyPath(TestEntity1.testDate)),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -234,7 +234,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Bool>(.average(#keyPath(TestEntity1.testBoolean))), Select<TestEntity1, Bool>(.average(#keyPath(TestEntity1.testBoolean))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -244,7 +244,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int8>(.average(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int8>(.average(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -254,7 +254,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int16>(.average(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int16>(.average(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -264,7 +264,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int32>(.average(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int32>(.average(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -274,7 +274,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int64>(.average(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int64>(.average(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -284,7 +284,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int>(.average(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int>(.average(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -294,7 +294,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Double>(.average(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Double>(.average(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -304,7 +304,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Float>(.average(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Float>(.average(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -314,7 +314,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSNumber>(.average(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, NSNumber>(.average(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -324,7 +324,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDecimalNumber>(.average(#keyPath(TestEntity1.testDecimal))), Select<TestEntity1, NSDecimalNumber>(.average(#keyPath(TestEntity1.testDecimal))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -334,7 +334,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<String>(.average(#keyPath(TestEntity1.testString))), Select<TestEntity1, String>(.average(#keyPath(TestEntity1.testString))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -343,7 +343,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSString>(.average(#keyPath(TestEntity1.testString))), Select<TestEntity1, NSString>(.average(#keyPath(TestEntity1.testString))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -352,7 +352,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Data>(.average(#keyPath(TestEntity1.testData))), Select<TestEntity1, Data>(.average(#keyPath(TestEntity1.testData))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -361,7 +361,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSData>(.average(#keyPath(TestEntity1.testData))), Select<TestEntity1, NSData>(.average(#keyPath(TestEntity1.testData))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -370,7 +370,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Date>(.average(#keyPath(TestEntity1.testDate))), Select<TestEntity1, Date>(.average(#keyPath(TestEntity1.testDate))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -379,7 +379,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDate>(.average(#keyPath(TestEntity1.testDate))), Select<TestEntity1, NSDate>(.average(#keyPath(TestEntity1.testDate))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -388,7 +388,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSManagedObjectID>(#keyPath(TestEntity1.testEntityID)), Select<TestEntity1, NSManagedObjectID>(#keyPath(TestEntity1.testEntityID)),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -412,7 +412,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Bool>(.count(#keyPath(TestEntity1.testBoolean))), Select<TestEntity1, Bool>(.count(#keyPath(TestEntity1.testBoolean))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -422,7 +422,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int8>(.count(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int8>(.count(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -432,7 +432,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int16>(.count(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int16>(.count(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -442,7 +442,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int32>(.count(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int32>(.count(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -452,7 +452,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int64>(.count(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int64>(.count(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -462,7 +462,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int>(.count(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int>(.count(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -472,7 +472,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Double>(.count(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Double>(.count(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -482,7 +482,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Float>(.count(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Float>(.count(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -492,7 +492,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSNumber>(.count(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, NSNumber>(.count(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -502,7 +502,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDecimalNumber>(.count(#keyPath(TestEntity1.testDecimal))), Select<TestEntity1, NSDecimalNumber>(.count(#keyPath(TestEntity1.testDecimal))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -511,7 +511,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<String>(.count(#keyPath(TestEntity1.testString))), Select<TestEntity1, String>(.count(#keyPath(TestEntity1.testString))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -520,7 +520,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSString>(.count(#keyPath(TestEntity1.testString))), Select<TestEntity1, NSString>(.count(#keyPath(TestEntity1.testString))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -529,7 +529,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Data>(.count(#keyPath(TestEntity1.testData))), Select<TestEntity1, Data>(.count(#keyPath(TestEntity1.testData))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -538,7 +538,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSData>(.count(#keyPath(TestEntity1.testData))), Select<TestEntity1, NSData>(.count(#keyPath(TestEntity1.testData))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -547,7 +547,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Date>(.count(#keyPath(TestEntity1.testDate))), Select<TestEntity1, Date>(.count(#keyPath(TestEntity1.testDate))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -556,7 +556,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDate>(.count(#keyPath(TestEntity1.testDate))), Select<TestEntity1, NSDate>(.count(#keyPath(TestEntity1.testDate))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -565,7 +565,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSManagedObjectID>(.count(#keyPath(TestEntity1.testEntityID))), Select<TestEntity1, NSManagedObjectID>(.count(#keyPath(TestEntity1.testEntityID))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -589,7 +589,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Bool>(.maximum(#keyPath(TestEntity1.testBoolean))), Select<TestEntity1, Bool>(.maximum(#keyPath(TestEntity1.testBoolean))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -599,7 +599,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int8>(.maximum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int8>(.maximum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -609,7 +609,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int16>(.maximum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int16>(.maximum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -619,7 +619,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int32>(.maximum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int32>(.maximum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -629,7 +629,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int64>(.maximum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int64>(.maximum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -639,7 +639,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int>(.maximum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int>(.maximum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -649,7 +649,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Double>(.maximum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Double>(.maximum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -659,7 +659,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Float>(.maximum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Float>(.maximum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -669,7 +669,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSNumber>(.maximum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, NSNumber>(.maximum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -679,7 +679,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDecimalNumber>(.maximum(#keyPath(TestEntity1.testDecimal))), Select<TestEntity1, NSDecimalNumber>(.maximum(#keyPath(TestEntity1.testDecimal))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -689,7 +689,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<String>(.maximum(#keyPath(TestEntity1.testString))), Select<TestEntity1, String>(.maximum(#keyPath(TestEntity1.testString))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -699,7 +699,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSString>(.maximum(#keyPath(TestEntity1.testString))), Select<TestEntity1, NSString>(.maximum(#keyPath(TestEntity1.testString))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -709,7 +709,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Data>(.maximum(#keyPath(TestEntity1.testData))), Select<TestEntity1, Data>(.maximum(#keyPath(TestEntity1.testData))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -719,7 +719,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSData>(.maximum(#keyPath(TestEntity1.testData))), Select<TestEntity1, NSData>(.maximum(#keyPath(TestEntity1.testData))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -729,7 +729,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Date>(.maximum(#keyPath(TestEntity1.testDate))), Select<TestEntity1, Date>(.maximum(#keyPath(TestEntity1.testDate))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -739,7 +739,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDate>(.maximum(#keyPath(TestEntity1.testDate))), Select<TestEntity1, NSDate>(.maximum(#keyPath(TestEntity1.testDate))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -749,7 +749,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSManagedObjectID>(.maximum(#keyPath(TestEntity1.testEntityID))), Select<TestEntity1, NSManagedObjectID>(.maximum(#keyPath(TestEntity1.testEntityID))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -773,7 +773,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Bool>(.minimum(#keyPath(TestEntity1.testBoolean))), Select<TestEntity1, Bool>(.minimum(#keyPath(TestEntity1.testBoolean))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -783,7 +783,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int8>(.minimum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int8>(.minimum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -793,7 +793,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int16>(.minimum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int16>(.minimum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -803,7 +803,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int32>(.minimum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int32>(.minimum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -813,7 +813,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int64>(.minimum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int64>(.minimum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -823,7 +823,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int>(.minimum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int>(.minimum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -833,7 +833,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Double>(.minimum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Double>(.minimum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -843,7 +843,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Float>(.minimum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Float>(.minimum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -853,7 +853,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSNumber>(.minimum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, NSNumber>(.minimum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -863,7 +863,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDecimalNumber>(.minimum(#keyPath(TestEntity1.testDecimal))), Select<TestEntity1, NSDecimalNumber>(.minimum(#keyPath(TestEntity1.testDecimal))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -873,7 +873,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<String>(.minimum(#keyPath(TestEntity1.testString))), Select<TestEntity1, String>(.minimum(#keyPath(TestEntity1.testString))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -883,7 +883,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSString>(.minimum(#keyPath(TestEntity1.testString))), Select<TestEntity1, NSString>(.minimum(#keyPath(TestEntity1.testString))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -893,7 +893,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Data>(.minimum(#keyPath(TestEntity1.testData))), Select<TestEntity1, Data>(.minimum(#keyPath(TestEntity1.testData))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -903,7 +903,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSData>(.minimum(#keyPath(TestEntity1.testData))), Select<TestEntity1, NSData>(.minimum(#keyPath(TestEntity1.testData))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -913,7 +913,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Date>(.minimum(#keyPath(TestEntity1.testDate))), Select<TestEntity1, Date>(.minimum(#keyPath(TestEntity1.testDate))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -923,7 +923,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDate>(.minimum(#keyPath(TestEntity1.testDate))), Select<TestEntity1, NSDate>(.minimum(#keyPath(TestEntity1.testDate))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -933,7 +933,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSManagedObjectID>(.minimum(#keyPath(TestEntity1.testEntityID))), Select<TestEntity1, NSManagedObjectID>(.minimum(#keyPath(TestEntity1.testEntityID))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -957,7 +957,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Bool>(.sum(#keyPath(TestEntity1.testBoolean))), Select<TestEntity1, Bool>(.sum(#keyPath(TestEntity1.testBoolean))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -967,7 +967,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int8>(.sum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int8>(.sum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -977,7 +977,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int16>(.sum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int16>(.sum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -987,7 +987,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int32>(.sum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int32>(.sum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -997,7 +997,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int64>(.sum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int64>(.sum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -1007,7 +1007,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int>(.sum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Int>(.sum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -1017,7 +1017,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Double>(.sum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Double>(.sum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -1027,7 +1027,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Float>(.sum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, Float>(.sum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -1037,7 +1037,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSNumber>(.sum(#keyPath(TestEntity1.testNumber))), Select<TestEntity1, NSNumber>(.sum(#keyPath(TestEntity1.testNumber))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -1047,7 +1047,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDecimalNumber>(.sum(#keyPath(TestEntity1.testDecimal))), Select<TestEntity1, NSDecimalNumber>(.sum(#keyPath(TestEntity1.testDecimal))),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -1057,7 +1057,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<String>(.sum(#keyPath(TestEntity1.testString))), Select<TestEntity1, String>(.sum(#keyPath(TestEntity1.testString))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1066,7 +1066,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSString>(.sum(#keyPath(TestEntity1.testString))), Select<TestEntity1, NSString>(.sum(#keyPath(TestEntity1.testString))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1075,7 +1075,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Data>(.sum(#keyPath(TestEntity1.testData))), Select<TestEntity1, Data>(.sum(#keyPath(TestEntity1.testData))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1084,7 +1084,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSData>(.sum(#keyPath(TestEntity1.testData))), Select<TestEntity1, NSData>(.sum(#keyPath(TestEntity1.testData))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1093,7 +1093,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Date>(.sum(#keyPath(TestEntity1.testDate))), Select<TestEntity1, Date>(.sum(#keyPath(TestEntity1.testDate))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1102,7 +1102,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDate>(.sum(#keyPath(TestEntity1.testDate))), Select<TestEntity1, NSDate>(.sum(#keyPath(TestEntity1.testDate))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1111,7 +1111,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSManagedObjectID>(.sum(#keyPath(TestEntity1.testEntityID))), Select<TestEntity1, NSManagedObjectID>(.sum(#keyPath(TestEntity1.testEntityID))),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1135,7 +1135,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Bool>(.objectID()), Select<TestEntity1, Bool>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1144,7 +1144,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int8>(.objectID()), Select<TestEntity1, Int8>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1153,7 +1153,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int16>(.objectID()), Select<TestEntity1, Int16>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1162,7 +1162,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int32>(.objectID()), Select<TestEntity1, Int32>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1171,7 +1171,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int64>(.objectID()), Select<TestEntity1, Int64>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1180,7 +1180,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Int>(.objectID()), Select<TestEntity1, Int>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1189,7 +1189,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Double>(.objectID()), Select<TestEntity1, Double>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1198,7 +1198,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Float>(.objectID()), Select<TestEntity1, Float>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1207,7 +1207,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSNumber>(.objectID()), Select<TestEntity1, NSNumber>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1216,7 +1216,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDecimalNumber>(.objectID()), Select<TestEntity1, NSDecimalNumber>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1225,7 +1225,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<String>(.objectID()), Select<TestEntity1, String>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1234,7 +1234,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSString>(.objectID()), Select<TestEntity1, NSString>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1243,7 +1243,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Data>(.objectID()), Select<TestEntity1, Data>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1252,7 +1252,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSData>(.objectID()), Select<TestEntity1, NSData>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1261,7 +1261,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<Date>(.objectID()), Select<TestEntity1, Date>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1270,7 +1270,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSDate>(.objectID()), Select<TestEntity1, NSDate>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNil(value) XCTAssertNil(value)
@@ -1279,7 +1279,7 @@ class QueryTests: BaseTestDataTestCase {
let value = stack.queryValue( let value = stack.queryValue(
from, from,
Select<NSManagedObjectID>(.objectID()), Select<TestEntity1, NSManagedObjectID>(.objectID()),
queryClauses queryClauses
) )
XCTAssertNotNil(value) XCTAssertNotNil(value)
@@ -1304,7 +1304,7 @@ class QueryTests: BaseTestDataTestCase {
let values = stack.queryAttributes( let values = stack.queryAttributes(
from, from,
Select( Select<TestEntity1, NSDictionary>(
#keyPath(TestEntity1.testBoolean), #keyPath(TestEntity1.testBoolean),
#keyPath(TestEntity1.testNumber), #keyPath(TestEntity1.testNumber),
#keyPath(TestEntity1.testDecimal), #keyPath(TestEntity1.testDecimal),
@@ -1355,7 +1355,7 @@ class QueryTests: BaseTestDataTestCase {
let values = stack.queryAttributes( let values = stack.queryAttributes(
from, from,
Select( Select<TestEntity1, NSDictionary>(
.sum(#keyPath(TestEntity1.testBoolean)), .sum(#keyPath(TestEntity1.testBoolean)),
.count(#keyPath(TestEntity1.testNumber)), .count(#keyPath(TestEntity1.testNumber)),
.maximum(#keyPath(TestEntity1.testNumber)), .maximum(#keyPath(TestEntity1.testNumber)),

View File

@@ -38,7 +38,7 @@ final class SelectTests: XCTestCase {
do { do {
let term: SelectTerm = "attribute" let term: SelectTerm<NSManagedObject> = "attribute"
XCTAssertEqual(term, SelectTerm.attribute("attribute")) XCTAssertEqual(term, SelectTerm.attribute("attribute"))
XCTAssertNotEqual(term, SelectTerm.attribute("attribute2")) XCTAssertNotEqual(term, SelectTerm.attribute("attribute2"))
XCTAssertNotEqual(term, SelectTerm.average("attribute")) XCTAssertNotEqual(term, SelectTerm.average("attribute"))
@@ -58,7 +58,7 @@ final class SelectTests: XCTestCase {
} }
do { do {
let term = SelectTerm.attribute("attribute") let term = SelectTerm<NSManagedObject>.attribute("attribute")
XCTAssertNotEqual(term, SelectTerm.attribute("attribute2")) XCTAssertNotEqual(term, SelectTerm.attribute("attribute2"))
XCTAssertNotEqual(term, SelectTerm.average("attribute")) XCTAssertNotEqual(term, SelectTerm.average("attribute"))
XCTAssertNotEqual(term, SelectTerm.count("attribute")) XCTAssertNotEqual(term, SelectTerm.count("attribute"))
@@ -82,7 +82,7 @@ final class SelectTests: XCTestCase {
do { do {
let term = SelectTerm.average("attribute") let term = SelectTerm<NSManagedObject>.average("attribute")
XCTAssertEqual(term, SelectTerm.average("attribute")) XCTAssertEqual(term, SelectTerm.average("attribute"))
XCTAssertNotEqual(term, SelectTerm.average("attribute", as: "alias")) XCTAssertNotEqual(term, SelectTerm.average("attribute", as: "alias"))
XCTAssertNotEqual(term, SelectTerm.average("attribute2")) XCTAssertNotEqual(term, SelectTerm.average("attribute2"))
@@ -106,7 +106,7 @@ final class SelectTests: XCTestCase {
} }
do { do {
let term = SelectTerm.average("attribute", as: "alias") let term = SelectTerm<NSManagedObject>.average("attribute", as: "alias")
XCTAssertEqual(term, SelectTerm.average("attribute", as: "alias")) XCTAssertEqual(term, SelectTerm.average("attribute", as: "alias"))
XCTAssertNotEqual(term, SelectTerm.average("attribute", as: "alias2")) XCTAssertNotEqual(term, SelectTerm.average("attribute", as: "alias2"))
XCTAssertNotEqual(term, SelectTerm.average("attribute2")) XCTAssertNotEqual(term, SelectTerm.average("attribute2"))
@@ -135,7 +135,7 @@ final class SelectTests: XCTestCase {
do { do {
let term = SelectTerm.count("attribute") let term = SelectTerm<NSManagedObject>.count("attribute")
XCTAssertEqual(term, SelectTerm.count("attribute")) XCTAssertEqual(term, SelectTerm.count("attribute"))
XCTAssertNotEqual(term, SelectTerm.count("attribute", as: "alias")) XCTAssertNotEqual(term, SelectTerm.count("attribute", as: "alias"))
XCTAssertNotEqual(term, SelectTerm.count("attribute2")) XCTAssertNotEqual(term, SelectTerm.count("attribute2"))
@@ -159,7 +159,7 @@ final class SelectTests: XCTestCase {
} }
do { do {
let term = SelectTerm.count("attribute", as: "alias") let term = SelectTerm<NSManagedObject>.count("attribute", as: "alias")
XCTAssertEqual(term, SelectTerm.count("attribute", as: "alias")) XCTAssertEqual(term, SelectTerm.count("attribute", as: "alias"))
XCTAssertNotEqual(term, SelectTerm.count("attribute", as: "alias2")) XCTAssertNotEqual(term, SelectTerm.count("attribute", as: "alias2"))
XCTAssertNotEqual(term, SelectTerm.count("attribute2")) XCTAssertNotEqual(term, SelectTerm.count("attribute2"))
@@ -188,7 +188,7 @@ final class SelectTests: XCTestCase {
do { do {
let term = SelectTerm.maximum("attribute") let term = SelectTerm<NSManagedObject>.maximum("attribute")
XCTAssertEqual(term, SelectTerm.maximum("attribute")) XCTAssertEqual(term, SelectTerm.maximum("attribute"))
XCTAssertNotEqual(term, SelectTerm.maximum("attribute", as: "alias")) XCTAssertNotEqual(term, SelectTerm.maximum("attribute", as: "alias"))
XCTAssertNotEqual(term, SelectTerm.maximum("attribute2")) XCTAssertNotEqual(term, SelectTerm.maximum("attribute2"))
@@ -212,7 +212,7 @@ final class SelectTests: XCTestCase {
} }
do { do {
let term = SelectTerm.maximum("attribute", as: "alias") let term = SelectTerm<NSManagedObject>.maximum("attribute", as: "alias")
XCTAssertEqual(term, SelectTerm.maximum("attribute", as: "alias")) XCTAssertEqual(term, SelectTerm.maximum("attribute", as: "alias"))
XCTAssertNotEqual(term, SelectTerm.maximum("attribute", as: "alias2")) XCTAssertNotEqual(term, SelectTerm.maximum("attribute", as: "alias2"))
XCTAssertNotEqual(term, SelectTerm.maximum("attribute2")) XCTAssertNotEqual(term, SelectTerm.maximum("attribute2"))
@@ -241,7 +241,7 @@ final class SelectTests: XCTestCase {
do { do {
let term = SelectTerm.minimum("attribute") let term = SelectTerm<NSManagedObject>.minimum("attribute")
XCTAssertEqual(term, SelectTerm.minimum("attribute")) XCTAssertEqual(term, SelectTerm.minimum("attribute"))
XCTAssertNotEqual(term, SelectTerm.minimum("attribute", as: "alias")) XCTAssertNotEqual(term, SelectTerm.minimum("attribute", as: "alias"))
XCTAssertNotEqual(term, SelectTerm.minimum("attribute2")) XCTAssertNotEqual(term, SelectTerm.minimum("attribute2"))
@@ -265,7 +265,7 @@ final class SelectTests: XCTestCase {
} }
do { do {
let term = SelectTerm.minimum("attribute", as: "alias") let term = SelectTerm<NSManagedObject>.minimum("attribute", as: "alias")
XCTAssertEqual(term, SelectTerm.minimum("attribute", as: "alias")) XCTAssertEqual(term, SelectTerm.minimum("attribute", as: "alias"))
XCTAssertNotEqual(term, SelectTerm.minimum("attribute", as: "alias2")) XCTAssertNotEqual(term, SelectTerm.minimum("attribute", as: "alias2"))
XCTAssertNotEqual(term, SelectTerm.minimum("attribute2")) XCTAssertNotEqual(term, SelectTerm.minimum("attribute2"))
@@ -294,7 +294,7 @@ final class SelectTests: XCTestCase {
do { do {
let term = SelectTerm.sum("attribute") let term = SelectTerm<NSManagedObject>.sum("attribute")
XCTAssertEqual(term, SelectTerm.sum("attribute")) XCTAssertEqual(term, SelectTerm.sum("attribute"))
XCTAssertNotEqual(term, SelectTerm.sum("attribute", as: "alias")) XCTAssertNotEqual(term, SelectTerm.sum("attribute", as: "alias"))
XCTAssertNotEqual(term, SelectTerm.sum("attribute2")) XCTAssertNotEqual(term, SelectTerm.sum("attribute2"))
@@ -318,7 +318,7 @@ final class SelectTests: XCTestCase {
} }
do { do {
let term = SelectTerm.sum("attribute", as: "alias") let term = SelectTerm<NSManagedObject>.sum("attribute", as: "alias")
XCTAssertEqual(term, SelectTerm.sum("attribute", as: "alias")) XCTAssertEqual(term, SelectTerm.sum("attribute", as: "alias"))
XCTAssertNotEqual(term, SelectTerm.sum("attribute", as: "alias2")) XCTAssertNotEqual(term, SelectTerm.sum("attribute", as: "alias2"))
XCTAssertNotEqual(term, SelectTerm.sum("attribute2")) XCTAssertNotEqual(term, SelectTerm.sum("attribute2"))
@@ -347,7 +347,7 @@ final class SelectTests: XCTestCase {
do { do {
let term = SelectTerm.objectID() let term = SelectTerm<NSManagedObject>.objectID()
XCTAssertEqual(term, SelectTerm.objectID()) XCTAssertEqual(term, SelectTerm.objectID())
XCTAssertNotEqual(term, SelectTerm.objectID(as: "alias")) XCTAssertNotEqual(term, SelectTerm.objectID(as: "alias"))
XCTAssertNotEqual(term, SelectTerm.attribute("attribute")) XCTAssertNotEqual(term, SelectTerm.attribute("attribute"))
@@ -368,7 +368,7 @@ final class SelectTests: XCTestCase {
} }
do { do {
let term = SelectTerm.objectID(as: "alias") let term = SelectTerm<NSManagedObject>.objectID(as: "alias")
XCTAssertEqual(term, SelectTerm.objectID(as: "alias")) XCTAssertEqual(term, SelectTerm.objectID(as: "alias"))
XCTAssertNotEqual(term, SelectTerm.objectID(as: "alias2")) XCTAssertNotEqual(term, SelectTerm.objectID(as: "alias2"))
XCTAssertNotEqual(term, SelectTerm.objectID()) XCTAssertNotEqual(term, SelectTerm.objectID())
@@ -393,12 +393,12 @@ final class SelectTests: XCTestCase {
@objc @objc
dynamic func test_ThatSelectClauses_ConfigureCorrectly() { dynamic func test_ThatSelectClauses_ConfigureCorrectly() {
let term1 = SelectTerm.attribute("attribute1") let term1 = SelectTerm<NSManagedObject>.attribute("attribute1")
let term2 = SelectTerm.attribute("attribute2") let term2 = SelectTerm<NSManagedObject>.attribute("attribute2")
let term3 = SelectTerm.attribute("attribute3") let term3 = SelectTerm<NSManagedObject>.attribute("attribute3")
do { do {
let select = Select<Int>(term1, term2, term3) let select = Select<NSManagedObject, Int>(term1, term2, term3)
XCTAssertEqual(select.selectTerms, [term1, term2, term3]) XCTAssertEqual(select.selectTerms, [term1, term2, term3])
XCTAssertNotEqual(select.selectTerms, [term1, term3, term2]) XCTAssertNotEqual(select.selectTerms, [term1, term3, term2])
XCTAssertNotEqual(select.selectTerms, [term2, term1, term3]) XCTAssertNotEqual(select.selectTerms, [term2, term1, term3])
@@ -408,7 +408,7 @@ final class SelectTests: XCTestCase {
} }
do { do {
let select = Select<Int>([term1, term2, term3]) let select = Select<NSManagedObject, Int>([term1, term2, term3])
XCTAssertEqual(select.selectTerms, [term1, term2, term3]) XCTAssertEqual(select.selectTerms, [term1, term2, term3])
XCTAssertNotEqual(select.selectTerms, [term1, term3, term2]) XCTAssertNotEqual(select.selectTerms, [term1, term3, term2])
XCTAssertNotEqual(select.selectTerms, [term2, term1, term3]) XCTAssertNotEqual(select.selectTerms, [term2, term1, term3])

View File

@@ -354,7 +354,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? { public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<D, U>, _ queryClauses: QueryClause...) -> U? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -373,7 +373,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? { public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<D, U>, _ queryClauses: [QueryClause]) -> U? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -402,7 +402,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? { public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<D, NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),
@@ -421,7 +421,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? { public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<D, NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
CoreStore.assert( CoreStore.assert(
self.isRunningInAllowedQueue(), self.isRunningInAllowedQueue(),

View File

@@ -35,7 +35,7 @@ import CoreData
- SeeAlso: `SelectTerm` - SeeAlso: `SelectTerm`
*/ */
@objc @objc
public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType { public final class CSSelectTerm: NSObject {
/** /**
Provides a `CSSelectTerm` to a `CSSelect` clause for querying an entity attribute. Provides a `CSSelectTerm` to a `CSSelect` clause for querying an entity attribute.
@@ -175,11 +175,11 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
// MARK: CoreStoreObjectiveCType // MARK: CoreStoreObjectiveCType
public let bridgeToSwift: SelectTerm public let bridgeToSwift: SelectTerm<NSManagedObject>
public init(_ swiftValue: SelectTerm) { public init<D: NSManagedObject>(_ swiftValue: SelectTerm<D>) {
self.bridgeToSwift = swiftValue self.bridgeToSwift = swiftValue.downcast()
super.init() super.init()
} }
} }
@@ -187,7 +187,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
// MARK: - SelectTerm // MARK: - SelectTerm
extension SelectTerm: CoreStoreSwiftType { extension SelectTerm where D: NSManagedObject {
// MARK: CoreStoreSwiftType // MARK: CoreStoreSwiftType
@@ -195,6 +195,24 @@ extension SelectTerm: CoreStoreSwiftType {
return CSSelectTerm(self) return CSSelectTerm(self)
} }
// MARK: FilePrivate
fileprivate func downcast() -> SelectTerm<NSManagedObject> {
switch self {
case ._attribute(let keyPath):
return SelectTerm<NSManagedObject>._attribute(keyPath)
case ._aggregate(let function, let keyPath, let alias, let nativeType):
return SelectTerm<NSManagedObject>._aggregate(function: function, keyPath: keyPath, alias: alias, nativeType: nativeType)
case ._identity(let alias, let nativeType):
return SelectTerm<NSManagedObject>._identity(alias: alias, nativeType: nativeType)
}
}
} }
@@ -221,7 +239,7 @@ public final class CSSelect: NSObject {
@objc @objc
public convenience init(numberTerm: CSSelectTerm) { public convenience init(numberTerm: CSSelectTerm) {
self.init(Select<NSNumber>(numberTerm.bridgeToSwift)) self.init(Select<NSManagedObject, NSNumber>(numberTerm.bridgeToSwift))
} }
/** /**
@@ -237,7 +255,7 @@ public final class CSSelect: NSObject {
@objc @objc
public convenience init(decimalTerm: CSSelectTerm) { public convenience init(decimalTerm: CSSelectTerm) {
self.init(Select<NSDecimalNumber>(decimalTerm.bridgeToSwift)) self.init(Select<NSManagedObject, NSDecimalNumber>(decimalTerm.bridgeToSwift))
} }
/** /**
@@ -253,7 +271,7 @@ public final class CSSelect: NSObject {
@objc @objc
public convenience init(stringTerm: CSSelectTerm) { public convenience init(stringTerm: CSSelectTerm) {
self.init(Select<NSString>(stringTerm.bridgeToSwift)) self.init(Select<NSManagedObject, NSString>(stringTerm.bridgeToSwift))
} }
/** /**
@@ -269,7 +287,7 @@ public final class CSSelect: NSObject {
@objc @objc
public convenience init(dateTerm: CSSelectTerm) { public convenience init(dateTerm: CSSelectTerm) {
self.init(Select<Date>(dateTerm.bridgeToSwift)) self.init(Select<NSManagedObject, Date>(dateTerm.bridgeToSwift))
} }
/** /**
@@ -285,7 +303,7 @@ public final class CSSelect: NSObject {
@objc @objc
public convenience init(dataTerm: CSSelectTerm) { public convenience init(dataTerm: CSSelectTerm) {
self.init(Select<Data>(dataTerm.bridgeToSwift)) self.init(Select<NSManagedObject, Data>(dataTerm.bridgeToSwift))
} }
/** /**
@@ -300,7 +318,7 @@ public final class CSSelect: NSObject {
@objc @objc
public convenience init(objectIDTerm: ()) { public convenience init(objectIDTerm: ()) {
self.init(Select<NSManagedObjectID>(.objectID())) self.init(Select<NSManagedObject, NSManagedObjectID>(.objectID()))
} }
/** /**
@@ -316,7 +334,7 @@ public final class CSSelect: NSObject {
@objc @objc
public static func dictionaryForTerm(_ term: CSSelectTerm) -> CSSelect { public static func dictionaryForTerm(_ term: CSSelectTerm) -> CSSelect {
return self.init(Select<NSDictionary>(term.bridgeToSwift)) return self.init(Select<NSManagedObject, NSDictionary>(term.bridgeToSwift))
} }
/** /**
@@ -335,7 +353,7 @@ public final class CSSelect: NSObject {
@objc @objc
public static func dictionaryForTerms(_ terms: [CSSelectTerm]) -> CSSelect { public static func dictionaryForTerms(_ terms: [CSSelectTerm]) -> CSSelect {
return self.init(Select<NSDictionary>(terms.map { $0.bridgeToSwift })) return self.init(Select<NSManagedObject, NSDictionary>(terms.map { $0.bridgeToSwift }))
} }
@@ -365,18 +383,18 @@ public final class CSSelect: NSObject {
// MARK: CoreStoreObjectiveCType // MARK: CoreStoreObjectiveCType
public init<T: QueryableAttributeType>(_ swiftValue: Select<T>) { public init<D: NSManagedObject, T: QueryableAttributeType>(_ swiftValue: Select<D, T>) {
self.attributeType = T.cs_rawAttributeType self.attributeType = T.cs_rawAttributeType
self.selectTerms = swiftValue.selectTerms self.selectTerms = swiftValue.selectTerms.map({ $0.downcast() })
self.bridgeToSwift = swiftValue self.bridgeToSwift = swiftValue
super.init() super.init()
} }
public init<T>(_ swiftValue: Select<T>) { public init<D: NSManagedObject, T>(_ swiftValue: Select<D, T>) {
self.attributeType = .undefinedAttributeType self.attributeType = .undefinedAttributeType
self.selectTerms = swiftValue.selectTerms self.selectTerms = swiftValue.selectTerms.map({ $0.downcast() })
self.bridgeToSwift = swiftValue self.bridgeToSwift = swiftValue
super.init() super.init()
} }
@@ -385,7 +403,95 @@ public final class CSSelect: NSObject {
// MARK: Internal // MARK: Internal
internal let attributeType: NSAttributeType internal let attributeType: NSAttributeType
internal let selectTerms: [SelectTerm] internal let selectTerms: [SelectTerm<NSManagedObject>]
// MARK: Internal
internal func applyToFetchRequest(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) {
fetchRequest.includesPendingChanges = false
fetchRequest.resultType = .dictionaryResultType
func attributeDescription(for keyPath: String, in entity: NSEntityDescription) -> NSAttributeDescription? {
let components = keyPath.components(separatedBy: ".")
switch components.count {
case 0:
return nil
case 1:
return entity.attributesByName[components[0]]
default:
guard let relationship = entity.relationshipsByName[components[0]],
let destinationEntity = relationship.destinationEntity else {
return nil
}
return attributeDescription(
for: components.dropFirst().joined(separator: "."),
in: destinationEntity
)
}
}
var propertiesToFetch = [Any]()
for term in self.selectTerms {
switch term {
case ._attribute(let keyPath):
propertiesToFetch.append(keyPath)
case ._aggregate(let function, let keyPath, let alias, let nativeType):
let entityDescription = fetchRequest.entity!
if let attributeDescription = attributeDescription(for: keyPath, in: entityDescription) {
let expressionDescription = NSExpressionDescription()
expressionDescription.name = alias
if nativeType == .undefinedAttributeType {
expressionDescription.expressionResultType = attributeDescription.attributeType
}
else {
expressionDescription.expressionResultType = nativeType
}
expressionDescription.expression = NSExpression(
forFunction: function,
arguments: [NSExpression(forKeyPath: keyPath)]
)
propertiesToFetch.append(expressionDescription)
}
else {
CoreStore.log(
.warning,
message: "The key path \"\(keyPath)\" could not be resolved in entity \(cs_typeName(entityDescription.managedObjectClassName)) as an attribute and will be ignored by \(cs_typeName(self)) query clause."
)
}
case ._identity(let alias, let nativeType):
let expressionDescription = NSExpressionDescription()
expressionDescription.name = alias
if nativeType == .undefinedAttributeType {
expressionDescription.expressionResultType = .objectIDAttributeType
}
else {
expressionDescription.expressionResultType = nativeType
}
expressionDescription.expression = NSExpression.expressionForEvaluatedObject()
propertiesToFetch.append(expressionDescription)
}
}
fetchRequest.propertiesToFetch = propertiesToFetch
}
// MARK: Private // MARK: Private
@@ -396,7 +502,7 @@ public final class CSSelect: NSObject {
// MARK: - Select // MARK: - Select
extension Select: CoreStoreSwiftType { extension Select where D: NSManagedObject {
// MARK: CoreStoreSwiftType // MARK: CoreStoreSwiftType
@@ -404,4 +510,12 @@ extension Select: CoreStoreSwiftType {
return CSSelect(self) return CSSelect(self)
} }
// MARK: FilePrivate
fileprivate func downcast() -> Select<NSManagedObject, T> {
return Select<NSManagedObject, T>(self.selectTerms.map({ $0.downcast() }))
}
} }

View File

@@ -41,7 +41,7 @@ public protocol QueryChainableBuilderType {
associatedtype ResultType: SelectResultType associatedtype ResultType: SelectResultType
var from: From<ObjectType> { get set } var from: From<ObjectType> { get set }
var select: Select<ResultType> { get set } var select: Select<ObjectType, ResultType> { get set }
var queryClauses: [QueryClause] { get set } var queryClauses: [QueryClause] { get set }
} }
@@ -79,7 +79,7 @@ public struct QueryChainBuilder<D: DynamicObject, R: SelectResultType>: QueryCha
public typealias ResultType = R public typealias ResultType = R
public var from: From<D> public var from: From<D>
public var select: Select<R> public var select: Select<D, R>
public var queryClauses: [QueryClause] = [] public var queryClauses: [QueryClause] = []
} }
@@ -101,12 +101,12 @@ public struct SectionMonitorChainBuilder<D: DynamicObject>: SectionMonitorBuilde
public extension From { public extension From {
public func select<R>(_ resultType: R.Type, _ selectTerm: SelectTerm, _ selectTerms: SelectTerm...) -> QueryChainBuilder<D, R> { public func select<R>(_ resultType: R.Type, _ selectTerm: SelectTerm<D>, _ selectTerms: SelectTerm<D>...) -> QueryChainBuilder<D, R> {
return self.select(resultType, [selectTerm] + selectTerms) return self.select(resultType, [selectTerm] + selectTerms)
} }
public func select<R>(_ resultType: R.Type, _ selectTerms: [SelectTerm]) -> QueryChainBuilder<D, R> { public func select<R>(_ resultType: R.Type, _ selectTerms: [SelectTerm<D>]) -> QueryChainBuilder<D, R> {
return .init( return .init(
from: self, from: self,
@@ -170,6 +170,97 @@ public extension From {
} }
} }
public extension From where D: NSManagedObject {
public func select<R>(_ keyPath: KeyPath<D, R>) -> QueryChainBuilder<D, R> {
return self.select(R.self, [SelectTerm<D>.attribute(keyPath)])
}
@available(OSX 10.12, *)
public func sectionBy<T>(_ sectionKeyPath: KeyPath<D, T>) -> SectionMonitorChainBuilder<D> {
return self.sectionBy(sectionKeyPath._kvcKeyPathString!, { $0 })
}
@available(OSX 10.12, *)
public func sectionBy<T>(_ sectionKeyPath: KeyPath<D, T>, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> SectionMonitorChainBuilder<D> {
return self.sectionBy(sectionKeyPath._kvcKeyPathString!, sectionIndexTransformer)
}
}
public extension From where D: CoreStoreObject {
public func select<R>(_ keyPath: KeyPath<D, ValueContainer<D>.Required<R>>) -> QueryChainBuilder<D, R> {
return self.select(R.self, [SelectTerm<D>.attribute(keyPath)])
}
public func select<R>(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<R>>) -> QueryChainBuilder<D, R> {
return self.select(R.self, [SelectTerm<D>.attribute(keyPath)])
}
public func select<R>(_ keyPath: KeyPath<D, TransformableContainer<D>.Required<R>>) -> QueryChainBuilder<D, R> {
return self.select(R.self, [SelectTerm<D>.attribute(keyPath)])
}
public func select<R>(_ keyPath: KeyPath<D, TransformableContainer<D>.Optional<R>>) -> QueryChainBuilder<D, R> {
return self.select(R.self, [SelectTerm<D>.attribute(keyPath)])
}
@available(OSX 10.12, *)
public func sectionBy<T>(_ sectionKeyPath: KeyPath<D, ValueContainer<D>.Required<T>>) -> SectionMonitorChainBuilder<D> {
return self.sectionBy(D.meta[keyPath: sectionKeyPath].keyPath, { $0 })
}
@available(OSX 10.12, *)
public func sectionBy<T>(_ sectionKeyPath: KeyPath<D, ValueContainer<D>.Optional<T>>) -> SectionMonitorChainBuilder<D> {
return self.sectionBy(D.meta[keyPath: sectionKeyPath].keyPath, { $0 })
}
@available(OSX 10.12, *)
public func sectionBy<T>(_ sectionKeyPath: KeyPath<D, TransformableContainer<D>.Required<T>>) -> SectionMonitorChainBuilder<D> {
return self.sectionBy(D.meta[keyPath: sectionKeyPath].keyPath, { $0 })
}
@available(OSX 10.12, *)
public func sectionBy<T>(_ sectionKeyPath: KeyPath<D, TransformableContainer<D>.Optional<T>>) -> SectionMonitorChainBuilder<D> {
return self.sectionBy(D.meta[keyPath: sectionKeyPath].keyPath, { $0 })
}
@available(OSX 10.12, *)
public func sectionBy<T>(_ sectionKeyPath: KeyPath<D, ValueContainer<D>.Required<T>>, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> SectionMonitorChainBuilder<D> {
return self.sectionBy(D.meta[keyPath: sectionKeyPath].keyPath, sectionIndexTransformer)
}
@available(OSX 10.12, *)
public func sectionBy<T>(_ sectionKeyPath: KeyPath<D, ValueContainer<D>.Optional<T>>, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> SectionMonitorChainBuilder<D> {
return self.sectionBy(D.meta[keyPath: sectionKeyPath].keyPath, sectionIndexTransformer)
}
@available(OSX 10.12, *)
public func sectionBy<T>(_ sectionKeyPath: KeyPath<D, TransformableContainer<D>.Required<T>>, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> SectionMonitorChainBuilder<D> {
return self.sectionBy(D.meta[keyPath: sectionKeyPath].keyPath, sectionIndexTransformer)
}
@available(OSX 10.12, *)
public func sectionBy<T>(_ sectionKeyPath: KeyPath<D, TransformableContainer<D>.Optional<T>>, _ sectionIndexTransformer: @escaping (_ sectionName: String?) -> String?) -> SectionMonitorChainBuilder<D> {
return self.sectionBy(D.meta[keyPath: sectionKeyPath].keyPath, sectionIndexTransformer)
}
}
public extension FetchChainBuilder { public extension FetchChainBuilder {
public func `where`(_ clause: Where<D>) -> FetchChainBuilder<D> { public func `where`(_ clause: Where<D>) -> FetchChainBuilder<D> {
@@ -274,6 +365,37 @@ public extension QueryChainBuilder {
} }
} }
public extension QueryChainBuilder where D: NSManagedObject {
public func groupBy<T>(_ keyPath: KeyPath<D, T>) -> QueryChainBuilder<D, R> {
return self.groupBy(GroupBy<D>(keyPath))
}
}
public extension QueryChainBuilder where D: CoreStoreObject {
public func groupBy<T>(_ keyPath: KeyPath<D, ValueContainer<D>.Required<T>>) -> QueryChainBuilder<D, R> {
return self.groupBy(GroupBy<D>(keyPath))
}
public func groupBy<T>(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<T>>) -> QueryChainBuilder<D, R> {
return self.groupBy(GroupBy<D>(keyPath))
}
public func groupBy<T>(_ keyPath: KeyPath<D, TransformableContainer<D>.Required<T>>) -> QueryChainBuilder<D, R> {
return self.groupBy(GroupBy<D>(keyPath))
}
public func groupBy<T>(_ keyPath: KeyPath<D, TransformableContainer<D>.Optional<T>>) -> QueryChainBuilder<D, R> {
return self.groupBy(GroupBy<D>(keyPath))
}
}
@available(OSX 10.12, *) @available(OSX 10.12, *)
public extension SectionMonitorChainBuilder { public extension SectionMonitorChainBuilder {

View File

@@ -235,7 +235,7 @@ public extension CoreStore {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public static func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? { public static func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<D, U>, _ queryClauses: QueryClause...) -> U? {
return self.defaultStack.queryValue(from, selectClause, queryClauses) return self.defaultStack.queryValue(from, selectClause, queryClauses)
} }
@@ -250,7 +250,7 @@ public extension CoreStore {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public static func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? { public static func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<D, U>, _ queryClauses: [QueryClause]) -> U? {
return self.defaultStack.queryValue(from, selectClause, queryClauses) return self.defaultStack.queryValue(from, selectClause, queryClauses)
} }
@@ -271,7 +271,7 @@ public extension CoreStore {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public static func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? { public static func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<D, NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
return self.defaultStack.queryAttributes(from, selectClause, queryClauses) return self.defaultStack.queryAttributes(from, selectClause, queryClauses)
} }
@@ -286,7 +286,7 @@ public extension CoreStore {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public static func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? { public static func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<D, NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
return self.defaultStack.queryAttributes(from, selectClause, queryClauses) return self.defaultStack.queryAttributes(from, selectClause, queryClauses)
} }

View File

@@ -300,7 +300,7 @@ extension DataStack: FetchableSource, QueryableSource {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? { public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<D, U>, _ queryClauses: QueryClause...) -> U? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,
@@ -319,7 +319,7 @@ extension DataStack: FetchableSource, QueryableSource {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? { public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<D, U>, _ queryClauses: [QueryClause]) -> U? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,
@@ -348,7 +348,7 @@ extension DataStack: FetchableSource, QueryableSource {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? { public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<D, NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,
@@ -367,7 +367,7 @@ extension DataStack: FetchableSource, QueryableSource {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? { public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<D, NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
CoreStore.assert( CoreStore.assert(
Thread.isMainThread, Thread.isMainThread,

View File

@@ -103,6 +103,37 @@ public struct GroupBy<D: DynamicObject>: GroupByClause, QueryClause, Hashable {
} }
} }
public extension GroupBy where D: NSManagedObject {
public init<T>(_ keyPath: KeyPath<D, T>) {
self.init([keyPath._kvcKeyPathString!])
}
}
public extension GroupBy where D: CoreStoreObject {
public init<T>(_ keyPath: KeyPath<D, ValueContainer<D>.Required<T>>) {
self.init([D.meta[keyPath: keyPath].keyPath])
}
public init<T>(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<T>>) {
self.init([D.meta[keyPath: keyPath].keyPath])
}
public init<T>(_ keyPath: KeyPath<D, TransformableContainer<D>.Required<T>>) {
self.init([D.meta[keyPath: keyPath].keyPath])
}
public init<T>(_ keyPath: KeyPath<D, TransformableContainer<D>.Optional<T>>) {
self.init([D.meta[keyPath: keyPath].keyPath])
}
}
// MARK: - GroupByClause // MARK: - GroupByClause

View File

@@ -142,15 +142,14 @@ internal extension NSManagedObjectContext {
fetchRequest.fetchLimit = 0 fetchRequest.fetchLimit = 0
let selectTerms = selectClause.selectTerms selectClause.applyToFetchRequest(fetchRequest)
selectTerms.applyToFetchRequest(fetchRequest, owner: selectClause)
queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) } queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
guard storeFound else { guard storeFound else {
return nil return nil
} }
return self.queryValue(selectTerms, fetchRequest: fetchRequest.dynamicCast()) return self.queryValue(selectClause.selectTerms, fetchRequest: fetchRequest.dynamicCast())
} }
@nonobjc @nonobjc
@@ -161,7 +160,7 @@ internal extension NSManagedObjectContext {
fetchRequest.fetchLimit = 0 fetchRequest.fetchLimit = 0
selectClause.selectTerms.applyToFetchRequest(fetchRequest, owner: selectClause) selectClause.applyToFetchRequest(fetchRequest)
queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) } queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
guard storeFound else { guard storeFound else {

View File

@@ -279,51 +279,50 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
// MARK: QueryableSource // MARK: QueryableSource
@nonobjc @nonobjc
public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? { public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<D, U>, _ queryClauses: QueryClause...) -> U? {
return self.queryValue(from, selectClause, queryClauses) return self.queryValue(from, selectClause, queryClauses)
} }
@nonobjc @nonobjc
public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? { public func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<D, U>, _ queryClauses: [QueryClause]) -> U? {
let fetchRequest = CoreStoreFetchRequest() let fetchRequest = CoreStoreFetchRequest()
let storeFound = from.applyToFetchRequest(fetchRequest, context: self) let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
fetchRequest.fetchLimit = 0 fetchRequest.fetchLimit = 0
let selectTerms = selectClause.selectTerms selectClause.applyToFetchRequest(fetchRequest)
selectTerms.applyToFetchRequest(fetchRequest, owner: selectClause)
queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) } queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
guard storeFound else { guard storeFound else {
return nil return nil
} }
return self.queryValue(selectTerms, fetchRequest: fetchRequest) return self.queryValue(selectClause.selectTerms, fetchRequest: fetchRequest)
} }
@nonobjc @nonobjc
public func queryValue<B>(_ clauseChain: B) -> B.ResultType? where B : QueryChainableBuilderType, B.ResultType : QueryableAttributeType { public func queryValue<B>(_ clauseChain: B) -> B.ResultType? where B: QueryChainableBuilderType, B.ResultType: QueryableAttributeType {
return self.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses) return self.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses)
} }
@nonobjc @nonobjc
public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? { public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<D, NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
return self.queryAttributes(from, selectClause, queryClauses) return self.queryAttributes(from, selectClause, queryClauses)
} }
@nonobjc @nonobjc
public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? { public func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<D, NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
let fetchRequest = CoreStoreFetchRequest() let fetchRequest = CoreStoreFetchRequest()
let storeFound = from.applyToFetchRequest(fetchRequest, context: self) let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
fetchRequest.fetchLimit = 0 fetchRequest.fetchLimit = 0
selectClause.selectTerms.applyToFetchRequest(fetchRequest, owner: selectClause) selectClause.applyToFetchRequest(fetchRequest)
queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) } queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
guard storeFound else { guard storeFound else {
@@ -498,7 +497,7 @@ internal extension NSManagedObjectContext {
// MARK: Querying // MARK: Querying
@nonobjc @nonobjc
internal func queryValue<U: QueryableAttributeType>(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> U? { internal func queryValue<D, U: QueryableAttributeType>(_ selectTerms: [SelectTerm<D>], fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> U? {
var fetchResults: [Any]? var fetchResults: [Any]?
var fetchError: Error? var fetchError: Error?
@@ -516,9 +515,9 @@ internal extension NSManagedObjectContext {
if let fetchResults = fetchResults { if let fetchResults = fetchResults {
if let rawResult = fetchResults.first as? NSDictionary, if let rawResult = fetchResults.first as? NSDictionary,
let rawObject = rawResult[selectTerms.keyPathForFirstSelectTerm()] as? U.QueryableNativeType { let rawObject = rawResult[selectTerms.first!.keyPathString] as? U.QueryableNativeType {
return Select<U>.ReturnType.cs_fromQueryableNativeType(rawObject) return Select<D, U>.ReturnType.cs_fromQueryableNativeType(rawObject)
} }
return nil return nil
} }
@@ -531,7 +530,7 @@ internal extension NSManagedObjectContext {
} }
@nonobjc @nonobjc
internal func queryValue(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> Any? { internal func queryValue<D>(_ selectTerms: [SelectTerm<D>], fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> Any? {
var fetchResults: [Any]? var fetchResults: [Any]?
var fetchError: Error? var fetchError: Error?
@@ -549,7 +548,7 @@ internal extension NSManagedObjectContext {
if let fetchResults = fetchResults { if let fetchResults = fetchResults {
if let rawResult = fetchResults.first as? NSDictionary, if let rawResult = fetchResults.first as? NSDictionary,
let rawObject = rawResult[selectTerms.keyPathForFirstSelectTerm()] { let rawObject = rawResult[selectTerms.first!.keyPathString] {
return rawObject return rawObject
} }
@@ -581,7 +580,7 @@ internal extension NSManagedObjectContext {
} }
if let fetchResults = fetchResults { if let fetchResults = fetchResults {
return Select<NSDictionary>.ReturnType.cs_fromQueryResultsNativeType(fetchResults) return NSDictionary.cs_fromQueryResultsNativeType(fetchResults)
} }
CoreStore.log( CoreStore.log(

View File

@@ -44,7 +44,7 @@ public protocol QueryableSource: class {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<D, U>, _ queryClauses: QueryClause...) -> U?
/** /**
Queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. Queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
@@ -56,7 +56,7 @@ public protocol QueryableSource: class {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<D, U>, _ queryClauses: [QueryClause]) -> U?
// TODO: docs // TODO: docs
func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType
@@ -71,7 +71,7 @@ public protocol QueryableSource: class {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<D, NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]?
/** /**
Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
@@ -83,7 +83,7 @@ public protocol QueryableSource: class {
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. - parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter. - returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
*/ */
func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]? func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<D, NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]?
// TODO: docs // TODO: docs
func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary

View File

@@ -52,7 +52,7 @@ public protocol SelectAttributesResultType: SelectResultType {
/** /**
The `SelectTerm` is passed to the `Select` clause to indicate the attributes/aggregate keys to be queried. The `SelectTerm` is passed to the `Select` clause to indicate the attributes/aggregate keys to be queried.
*/ */
public enum SelectTerm: ExpressibleByStringLiteral, Hashable { public enum SelectTerm<D: DynamicObject>: ExpressibleByStringLiteral, Hashable {
/** /**
Provides a `SelectTerm` to a `Select` clause for querying an entity attribute. A shorter way to do the same is to assign from the string keypath directly: Provides a `SelectTerm` to a `Select` clause for querying an entity attribute. A shorter way to do the same is to assign from the string keypath directly:
@@ -74,7 +74,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter keyPath: the attribute name - parameter keyPath: the attribute name
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute - returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
*/ */
public static func attribute(_ keyPath: KeyPathString) -> SelectTerm { public static func attribute(_ keyPath: KeyPathString) -> SelectTerm<D> {
return ._attribute(keyPath) return ._attribute(keyPath)
} }
@@ -91,7 +91,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used - parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute - returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
*/ */
public static func average(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm { public static func average(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return ._aggregate( return ._aggregate(
function: "average:", function: "average:",
@@ -113,7 +113,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used - parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for a count query - returns: a `SelectTerm` to a `Select` clause for a count query
*/ */
public static func count(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm { public static func count(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return ._aggregate( return ._aggregate(
function: "count:", function: "count:",
@@ -135,7 +135,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used - parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute - returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
*/ */
public static func maximum(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm { public static func maximum(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return ._aggregate( return ._aggregate(
function: "max:", function: "max:",
@@ -157,7 +157,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used - parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute - returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
*/ */
public static func minimum(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm { public static func minimum(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return ._aggregate( return ._aggregate(
function: "min:", function: "min:",
@@ -179,7 +179,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used - parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute - returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
*/ */
public static func sum(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm { public static func sum(_ keyPath: KeyPathString, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return ._aggregate( return ._aggregate(
function: "sum:", function: "sum:",
@@ -202,7 +202,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "objecID" is used - parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "objecID" is used
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute - returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
*/ */
public static func objectID(as alias: KeyPathString? = nil) -> SelectTerm { public static func objectID(as alias: KeyPathString? = nil) -> SelectTerm<D> {
return ._identity( return ._identity(
alias: alias ?? "objectID", alias: alias ?? "objectID",
@@ -231,7 +231,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
// MARK: Equatable // MARK: Equatable
public static func == (lhs: SelectTerm, rhs: SelectTerm) -> Bool { public static func == (lhs: SelectTerm<D>, rhs: SelectTerm<D>) -> Bool {
switch (lhs, rhs) { switch (lhs, rhs) {
@@ -248,7 +248,9 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
case (._identity(let alias1, let nativeType1), ._identity(let alias2, let nativeType2)): case (._identity(let alias1, let nativeType1), ._identity(let alias2, let nativeType2)):
return alias1 == alias2 && nativeType1 == nativeType2 return alias1 == alias2 && nativeType1 == nativeType2
default: case (._attribute, _),
(._aggregate, _),
(._identity, _):
return false return false
} }
} }
@@ -277,6 +279,355 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
case _attribute(KeyPathString) case _attribute(KeyPathString)
case _aggregate(function: String, keyPath: KeyPathString, alias: String, nativeType: NSAttributeType) case _aggregate(function: String, keyPath: KeyPathString, alias: String, nativeType: NSAttributeType)
case _identity(alias: String, nativeType: NSAttributeType) case _identity(alias: String, nativeType: NSAttributeType)
internal var keyPathString: String {
switch self {
case ._attribute(let keyPath): return keyPath
case ._aggregate(_, _, let alias, _): return alias
case ._identity(let alias, _): return alias
}
}
}
extension SelectTerm where D: NSManagedObject {
/**
Provides a `SelectTerm` to a `Select` clause for querying an entity attribute.
- parameter keyPath: the attribute name
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
*/
public static func attribute<V>(_ keyPath: KeyPath<D, V>) -> SelectTerm<D> {
return self.attribute(keyPath._kvcKeyPathString!)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the average value of an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
*/
public static func average<V>(_ keyPath: KeyPath<D, V>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.average(keyPath._kvcKeyPathString!, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for a count query.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for a count query
*/
public static func count<V>(_ keyPath: KeyPath<D, V>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.count(keyPath._kvcKeyPathString!, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
*/
public static func maximum<V>(_ keyPath: KeyPath<D, V>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.maximum(keyPath._kvcKeyPathString!, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
*/
public static func minimum<V>(_ keyPath: KeyPath<D, V>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.minimum(keyPath._kvcKeyPathString!, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the sum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
*/
public static func sum<V>(_ keyPath: KeyPath<D, V>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.sum(keyPath._kvcKeyPathString!, as: alias)
}
}
extension SelectTerm where D: CoreStoreObject {
/**
Provides a `SelectTerm` to a `Select` clause for querying an entity attribute.
- parameter keyPath: the attribute name
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
*/
public static func attribute<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Required<V>>) -> SelectTerm<D> {
return self.attribute(D.meta[keyPath: keyPath].keyPath)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying an entity attribute.
- parameter keyPath: the attribute name
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
*/
public static func attribute<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<V>>) -> SelectTerm<D> {
return self.attribute(D.meta[keyPath: keyPath].keyPath)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying an entity attribute.
- parameter keyPath: the attribute name
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
*/
public static func attribute<V>(_ keyPath: KeyPath<D, TransformableContainer<D>.Required<V>>) -> SelectTerm<D> {
return self.attribute(D.meta[keyPath: keyPath].keyPath)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying an entity attribute.
- parameter keyPath: the attribute name
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
*/
public static func attribute<V>(_ keyPath: KeyPath<D, TransformableContainer<D>.Optional<V>>) -> SelectTerm<D> {
return self.attribute(D.meta[keyPath: keyPath].keyPath)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the average value of an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
*/
public static func average<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Required<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.average(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the average value of an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
*/
public static func average<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.average(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the average value of an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
*/
public static func average<V>(_ keyPath: KeyPath<D, TransformableContainer<D>.Required<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.average(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the average value of an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "average(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the average value of an attribute
*/
public static func average<V>(_ keyPath: KeyPath<D, TransformableContainer<D>.Optional<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.average(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for a count query.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for a count query
*/
public static func count<V>(_ keyPath: KeyPath<D,
ValueContainer<D>.Required<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.count(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for a count query.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for a count query
*/
public static func count<V>(_ keyPath: KeyPath<D,
ValueContainer<D>.Optional<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.count(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for a count query.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for a count query
*/
public static func count<V>(_ keyPath: KeyPath<D,
TransformableContainer<D>.Required<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.count(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for a count query.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "count(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for a count query
*/
public static func count<V>(_ keyPath: KeyPath<D,
TransformableContainer<D>.Optional<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.count(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
*/
public static func maximum<V>(_ keyPath: KeyPath<D,
ValueContainer<D>.Required<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.maximum(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
*/
public static func maximum<V>(_ keyPath: KeyPath<D,
ValueContainer<D>.Optional<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.maximum(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
*/
public static func maximum<V>(_ keyPath: KeyPath<D,
TransformableContainer<D>.Required<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.maximum(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "max(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the maximum value for an attribute
*/
public static func maximum<V>(_ keyPath: KeyPath<D,
TransformableContainer<D>.Optional<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.maximum(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
*/
public static func minimum<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Required<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.minimum(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
*/
public static func minimum<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.minimum(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
*/
public static func minimum<V>(_ keyPath: KeyPath<D, TransformableContainer<D>.Required<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.minimum(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "min(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the minimum value for an attribute
*/
public static func minimum<V>(_ keyPath: KeyPath<D, TransformableContainer<D>.Optional<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.minimum(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the sum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
*/
public static func sum<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Required<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.sum(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the sum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
*/
public static func sum<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.sum(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the sum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
*/
public static func sum<V>(_ keyPath: KeyPath<D, TransformableContainer<D>.Required<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.sum(D.meta[keyPath: keyPath].keyPath, as: alias)
}
/**
Provides a `SelectTerm` to a `Select` clause for querying the sum value for an attribute.
- parameter keyPath: the attribute name
- parameter alias: the dictionary key to use to access the result. Ignored when the query return value is not an `NSDictionary`. If `nil`, the default key "sum(<attributeName>)" is used
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
*/
public static func sum<V>(_ keyPath: KeyPath<D, TransformableContainer<D>.Optional<V>>, as alias: KeyPathString? = nil) -> SelectTerm<D> {
return self.sum(D.meta[keyPath: keyPath].keyPath, as: alias)
}
} }
@@ -308,12 +659,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
- parameter sortDescriptors: a series of `NSSortDescriptor`s - parameter sortDescriptors: a series of `NSSortDescriptor`s
*/ */
public struct Select<T: SelectResultType>: Hashable { public struct Select<D: DynamicObject, T: SelectResultType>: SelectClause, Hashable {
/**
The `SelectResultType` type for the query's return value
*/
public typealias ReturnType = T
/** /**
Initializes a `Select` clause with a list of `SelectTerm`s Initializes a `Select` clause with a list of `SelectTerm`s
@@ -321,7 +667,7 @@ public struct Select<T: SelectResultType>: Hashable {
- parameter selectTerm: a `SelectTerm` - parameter selectTerm: a `SelectTerm`
- parameter selectTerms: a series of `SelectTerm`s - parameter selectTerms: a series of `SelectTerm`s
*/ */
public init(_ selectTerm: SelectTerm, _ selectTerms: SelectTerm...) { public init(_ selectTerm: SelectTerm<D>, _ selectTerms: SelectTerm<D>...) {
self.selectTerms = [selectTerm] + selectTerms self.selectTerms = [selectTerm] + selectTerms
} }
@@ -331,7 +677,7 @@ public struct Select<T: SelectResultType>: Hashable {
- parameter selectTerms: a series of `SelectTerm`s - parameter selectTerms: a series of `SelectTerm`s
*/ */
public init(_ selectTerms: [SelectTerm]) { public init(_ selectTerms: [SelectTerm<D>]) {
self.selectTerms = selectTerms self.selectTerms = selectTerms
} }
@@ -339,12 +685,20 @@ public struct Select<T: SelectResultType>: Hashable {
// MARK: Equatable // MARK: Equatable
public static func == <T, U>(lhs: Select<T>, rhs: Select<U>) -> Bool { public static func == <T, U>(lhs: Select<D, T>, rhs: Select<D, U>) -> Bool {
return lhs.selectTerms == rhs.selectTerms return lhs.selectTerms == rhs.selectTerms
} }
// MARK: SelectClause
public typealias ObjectType = D
public typealias ReturnType = T
public let selectTerms: [SelectTerm<D>]
// MARK: Hashable // MARK: Hashable
public var hashValue: Int { public var hashValue: Int {
@@ -355,36 +709,7 @@ public struct Select<T: SelectResultType>: Hashable {
// MARK: Internal // MARK: Internal
internal let selectTerms: [SelectTerm] internal func applyToFetchRequest(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) {
}
public extension Select where T: NSManagedObjectID {
public init() {
self.init(.objectID())
}
}
// MARK: - NSDictionary: SelectAttributesResultType
extension NSDictionary: SelectAttributesResultType {
// MARK: SelectAttributesResultType
public static func cs_fromQueryResultsNativeType(_ result: [Any]) -> [[String : Any]] {
return result as! [[String: Any]]
}
}
// MARK: - Internal
internal extension Collection where Iterator.Element == SelectTerm {
internal func applyToFetchRequest<T>(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>, owner: T) {
fetchRequest.includesPendingChanges = false fetchRequest.includesPendingChanges = false
fetchRequest.resultType = .dictionaryResultType fetchRequest.resultType = .dictionaryResultType
@@ -414,7 +739,7 @@ internal extension Collection where Iterator.Element == SelectTerm {
} }
var propertiesToFetch = [Any]() var propertiesToFetch = [Any]()
for term in self { for term in self.selectTerms {
switch term { switch term {
@@ -445,7 +770,7 @@ internal extension Collection where Iterator.Element == SelectTerm {
CoreStore.log( CoreStore.log(
.warning, .warning,
message: "The key path \"\(keyPath)\" could not be resolved in entity \(cs_typeName(entityDescription.managedObjectClassName)) as an attribute and will be ignored by \(cs_typeName(owner)) query clause." message: "The key path \"\(keyPath)\" could not be resolved in entity \(cs_typeName(entityDescription.managedObjectClassName)) as an attribute and will be ignored by \(cs_typeName(self)) query clause."
) )
} }
@@ -468,19 +793,106 @@ internal extension Collection where Iterator.Element == SelectTerm {
fetchRequest.propertiesToFetch = propertiesToFetch fetchRequest.propertiesToFetch = propertiesToFetch
} }
}
internal func keyPathForFirstSelectTerm() -> KeyPathString { public extension Select where T: NSManagedObjectID {
switch self.first! { /**
Initializes a `Select` that queries for `NSManagedObjectID` results
*/
public init() {
case ._attribute(let keyPath): self.init(.objectID())
return keyPath }
}
case ._aggregate(_, _, let alias, _):
return alias public extension Select where D: NSManagedObject {
case ._identity(let alias, _): /**
return alias Initializes a `Select` that queries the value of an attribute pertained by a keyPath
} - parameter keyPath: the keyPath for the attribute
*/
public init(_ keyPath: KeyPath<D, T>) {
self.init(.attribute(keyPath))
}
}
public extension Select where D: CoreStoreObject, T: ImportableAttributeType {
/**
Initializes a `Select` that queries the value of an attribute pertained by a keyPath
- parameter keyPath: the keyPath for the attribute
*/
public init(_ keyPath: KeyPath<D, ValueContainer<D>.Required<T>>) {
self.init(.attribute(keyPath))
}
/**
Initializes a `Select` that queries the value of an attribute pertained by a keyPath
- parameter keyPath: the keyPath for the attribute
*/
public init(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<T>>) {
self.init(.attribute(keyPath))
}
}
public extension Select where D: CoreStoreObject, T: ImportableAttributeType & NSCoding & NSCopying {
/**
Initializes a `Select` that queries the value of an attribute pertained by a keyPath
- parameter keyPath: the keyPath for the attribute
*/
public init(_ keyPath: KeyPath<D, TransformableContainer<D>.Required<T>>) {
self.init(.attribute(keyPath))
}
/**
Initializes a `Select` that queries the value of an attribute pertained by a keyPath
- parameter keyPath: the keyPath for the attribute
*/
public init(_ keyPath: KeyPath<D, TransformableContainer<D>.Optional<T>>) {
self.init(.attribute(keyPath))
}
}
// MARK: - SelectClause
/**
Abstracts the `Select` clause for protocol utilities.
*/
public protocol SelectClause {
/**
The `DynamicObject` type associated with the clause
*/
associatedtype ObjectType: DynamicObject
/**
The `SelectResultType` type associated with the clause
*/
associatedtype ReturnType: SelectResultType
/**
The `SelectTerm`s for the query
*/
var selectTerms: [SelectTerm<ObjectType>] { get }
}
// MARK: - NSDictionary: SelectAttributesResultType
extension NSDictionary: SelectAttributesResultType {
// MARK: SelectAttributesResultType
public static func cs_fromQueryResultsNativeType(_ result: [Any]) -> [[String : Any]] {
return result as! [[String: Any]]
} }
} }