mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-16 05:56:50 +01:00
keyPath utilities for Select queries
This commit is contained in:
@@ -49,7 +49,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Bool>(#keyPath(TestEntity1.testBoolean)),
|
||||
Select<TestEntity1, Bool>(#keyPath(TestEntity1.testBoolean)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -59,7 +59,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int8>(#keyPath(TestEntity1.testNumber)),
|
||||
Select<TestEntity1, Int8>(#keyPath(TestEntity1.testNumber)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -69,7 +69,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int16>(#keyPath(TestEntity1.testNumber)),
|
||||
Select<TestEntity1, Int16>(#keyPath(TestEntity1.testNumber)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -79,7 +79,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int32>(#keyPath(TestEntity1.testNumber)),
|
||||
Select<TestEntity1, Int32>(#keyPath(TestEntity1.testNumber)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -89,7 +89,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int64>(#keyPath(TestEntity1.testNumber)),
|
||||
Select<TestEntity1, Int64>(#keyPath(TestEntity1.testNumber)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -99,7 +99,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int>(#keyPath(TestEntity1.testNumber)),
|
||||
Select<TestEntity1, Int>(#keyPath(TestEntity1.testNumber)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -109,7 +109,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Double>(#keyPath(TestEntity1.testNumber)),
|
||||
Select<TestEntity1, Double>(#keyPath(TestEntity1.testNumber)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -119,7 +119,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Float>(#keyPath(TestEntity1.testNumber)),
|
||||
Select<TestEntity1, Float>(#keyPath(TestEntity1.testNumber)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -129,7 +129,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSNumber>(#keyPath(TestEntity1.testNumber)),
|
||||
Select<TestEntity1, NSNumber>(#keyPath(TestEntity1.testNumber)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -139,7 +139,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDecimalNumber>(#keyPath(TestEntity1.testDecimal)),
|
||||
Select<TestEntity1, NSDecimalNumber>(#keyPath(TestEntity1.testDecimal)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -149,7 +149,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<String>(#keyPath(TestEntity1.testString)),
|
||||
Select<TestEntity1, String>(#keyPath(TestEntity1.testString)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -159,7 +159,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSString>(#keyPath(TestEntity1.testString)),
|
||||
Select<TestEntity1, NSString>(#keyPath(TestEntity1.testString)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -169,7 +169,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Data>(#keyPath(TestEntity1.testData)),
|
||||
Select<TestEntity1, Data>(#keyPath(TestEntity1.testData)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -179,7 +179,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSData>(#keyPath(TestEntity1.testData)),
|
||||
Select<TestEntity1, NSData>(#keyPath(TestEntity1.testData)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -189,7 +189,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Date>(#keyPath(TestEntity1.testDate)),
|
||||
Select<TestEntity1, Date>(#keyPath(TestEntity1.testDate)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -199,7 +199,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDate>(#keyPath(TestEntity1.testDate)),
|
||||
Select<TestEntity1, NSDate>(#keyPath(TestEntity1.testDate)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -209,7 +209,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSManagedObjectID>(#keyPath(TestEntity1.testDate)),
|
||||
Select<TestEntity1, NSManagedObjectID>(#keyPath(TestEntity1.testDate)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -234,7 +234,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Bool>(.average(#keyPath(TestEntity1.testBoolean))),
|
||||
Select<TestEntity1, Bool>(.average(#keyPath(TestEntity1.testBoolean))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -244,7 +244,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int8>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int8>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -254,7 +254,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int16>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int16>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -264,7 +264,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int32>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int32>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -274,7 +274,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int64>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int64>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -284,7 +284,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -294,7 +294,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Double>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Double>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -304,7 +304,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Float>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Float>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -314,7 +314,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSNumber>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, NSNumber>(.average(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -324,7 +324,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDecimalNumber>(.average(#keyPath(TestEntity1.testDecimal))),
|
||||
Select<TestEntity1, NSDecimalNumber>(.average(#keyPath(TestEntity1.testDecimal))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -334,7 +334,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<String>(.average(#keyPath(TestEntity1.testString))),
|
||||
Select<TestEntity1, String>(.average(#keyPath(TestEntity1.testString))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -343,7 +343,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSString>(.average(#keyPath(TestEntity1.testString))),
|
||||
Select<TestEntity1, NSString>(.average(#keyPath(TestEntity1.testString))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -352,7 +352,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Data>(.average(#keyPath(TestEntity1.testData))),
|
||||
Select<TestEntity1, Data>(.average(#keyPath(TestEntity1.testData))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -361,7 +361,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSData>(.average(#keyPath(TestEntity1.testData))),
|
||||
Select<TestEntity1, NSData>(.average(#keyPath(TestEntity1.testData))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -370,7 +370,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Date>(.average(#keyPath(TestEntity1.testDate))),
|
||||
Select<TestEntity1, Date>(.average(#keyPath(TestEntity1.testDate))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -379,7 +379,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDate>(.average(#keyPath(TestEntity1.testDate))),
|
||||
Select<TestEntity1, NSDate>(.average(#keyPath(TestEntity1.testDate))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -388,7 +388,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSManagedObjectID>(#keyPath(TestEntity1.testEntityID)),
|
||||
Select<TestEntity1, NSManagedObjectID>(#keyPath(TestEntity1.testEntityID)),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -412,7 +412,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Bool>(.count(#keyPath(TestEntity1.testBoolean))),
|
||||
Select<TestEntity1, Bool>(.count(#keyPath(TestEntity1.testBoolean))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -422,7 +422,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int8>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int8>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -432,7 +432,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int16>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int16>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -442,7 +442,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int32>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int32>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -452,7 +452,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int64>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int64>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -462,7 +462,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -472,7 +472,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Double>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Double>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -482,7 +482,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Float>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Float>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -492,7 +492,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSNumber>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, NSNumber>(.count(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -502,7 +502,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDecimalNumber>(.count(#keyPath(TestEntity1.testDecimal))),
|
||||
Select<TestEntity1, NSDecimalNumber>(.count(#keyPath(TestEntity1.testDecimal))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -511,7 +511,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<String>(.count(#keyPath(TestEntity1.testString))),
|
||||
Select<TestEntity1, String>(.count(#keyPath(TestEntity1.testString))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -520,7 +520,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSString>(.count(#keyPath(TestEntity1.testString))),
|
||||
Select<TestEntity1, NSString>(.count(#keyPath(TestEntity1.testString))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -529,7 +529,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Data>(.count(#keyPath(TestEntity1.testData))),
|
||||
Select<TestEntity1, Data>(.count(#keyPath(TestEntity1.testData))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -538,7 +538,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSData>(.count(#keyPath(TestEntity1.testData))),
|
||||
Select<TestEntity1, NSData>(.count(#keyPath(TestEntity1.testData))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -547,7 +547,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Date>(.count(#keyPath(TestEntity1.testDate))),
|
||||
Select<TestEntity1, Date>(.count(#keyPath(TestEntity1.testDate))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -556,7 +556,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDate>(.count(#keyPath(TestEntity1.testDate))),
|
||||
Select<TestEntity1, NSDate>(.count(#keyPath(TestEntity1.testDate))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -565,7 +565,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSManagedObjectID>(.count(#keyPath(TestEntity1.testEntityID))),
|
||||
Select<TestEntity1, NSManagedObjectID>(.count(#keyPath(TestEntity1.testEntityID))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -589,7 +589,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Bool>(.maximum(#keyPath(TestEntity1.testBoolean))),
|
||||
Select<TestEntity1, Bool>(.maximum(#keyPath(TestEntity1.testBoolean))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -599,7 +599,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int8>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int8>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -609,7 +609,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int16>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int16>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -619,7 +619,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int32>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int32>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -629,7 +629,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int64>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int64>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -639,7 +639,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -649,7 +649,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Double>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Double>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -659,7 +659,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Float>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Float>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -669,7 +669,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSNumber>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, NSNumber>(.maximum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -679,7 +679,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDecimalNumber>(.maximum(#keyPath(TestEntity1.testDecimal))),
|
||||
Select<TestEntity1, NSDecimalNumber>(.maximum(#keyPath(TestEntity1.testDecimal))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -689,7 +689,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<String>(.maximum(#keyPath(TestEntity1.testString))),
|
||||
Select<TestEntity1, String>(.maximum(#keyPath(TestEntity1.testString))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -699,7 +699,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSString>(.maximum(#keyPath(TestEntity1.testString))),
|
||||
Select<TestEntity1, NSString>(.maximum(#keyPath(TestEntity1.testString))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -709,7 +709,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Data>(.maximum(#keyPath(TestEntity1.testData))),
|
||||
Select<TestEntity1, Data>(.maximum(#keyPath(TestEntity1.testData))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -719,7 +719,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSData>(.maximum(#keyPath(TestEntity1.testData))),
|
||||
Select<TestEntity1, NSData>(.maximum(#keyPath(TestEntity1.testData))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -729,7 +729,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Date>(.maximum(#keyPath(TestEntity1.testDate))),
|
||||
Select<TestEntity1, Date>(.maximum(#keyPath(TestEntity1.testDate))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -739,7 +739,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDate>(.maximum(#keyPath(TestEntity1.testDate))),
|
||||
Select<TestEntity1, NSDate>(.maximum(#keyPath(TestEntity1.testDate))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -749,7 +749,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSManagedObjectID>(.maximum(#keyPath(TestEntity1.testEntityID))),
|
||||
Select<TestEntity1, NSManagedObjectID>(.maximum(#keyPath(TestEntity1.testEntityID))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -773,7 +773,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Bool>(.minimum(#keyPath(TestEntity1.testBoolean))),
|
||||
Select<TestEntity1, Bool>(.minimum(#keyPath(TestEntity1.testBoolean))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -783,7 +783,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int8>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int8>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -793,7 +793,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int16>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int16>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -803,7 +803,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int32>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int32>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -813,7 +813,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int64>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int64>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -823,7 +823,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -833,7 +833,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Double>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Double>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -843,7 +843,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Float>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Float>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -853,7 +853,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSNumber>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, NSNumber>(.minimum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -863,7 +863,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDecimalNumber>(.minimum(#keyPath(TestEntity1.testDecimal))),
|
||||
Select<TestEntity1, NSDecimalNumber>(.minimum(#keyPath(TestEntity1.testDecimal))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -873,7 +873,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<String>(.minimum(#keyPath(TestEntity1.testString))),
|
||||
Select<TestEntity1, String>(.minimum(#keyPath(TestEntity1.testString))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -883,7 +883,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSString>(.minimum(#keyPath(TestEntity1.testString))),
|
||||
Select<TestEntity1, NSString>(.minimum(#keyPath(TestEntity1.testString))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -893,7 +893,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Data>(.minimum(#keyPath(TestEntity1.testData))),
|
||||
Select<TestEntity1, Data>(.minimum(#keyPath(TestEntity1.testData))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -903,7 +903,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSData>(.minimum(#keyPath(TestEntity1.testData))),
|
||||
Select<TestEntity1, NSData>(.minimum(#keyPath(TestEntity1.testData))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -913,7 +913,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Date>(.minimum(#keyPath(TestEntity1.testDate))),
|
||||
Select<TestEntity1, Date>(.minimum(#keyPath(TestEntity1.testDate))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -923,7 +923,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDate>(.minimum(#keyPath(TestEntity1.testDate))),
|
||||
Select<TestEntity1, NSDate>(.minimum(#keyPath(TestEntity1.testDate))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -933,7 +933,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSManagedObjectID>(.minimum(#keyPath(TestEntity1.testEntityID))),
|
||||
Select<TestEntity1, NSManagedObjectID>(.minimum(#keyPath(TestEntity1.testEntityID))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -957,7 +957,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Bool>(.sum(#keyPath(TestEntity1.testBoolean))),
|
||||
Select<TestEntity1, Bool>(.sum(#keyPath(TestEntity1.testBoolean))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -967,7 +967,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int8>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int8>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -977,7 +977,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int16>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int16>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -987,7 +987,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int32>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int32>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -997,7 +997,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int64>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int64>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -1007,7 +1007,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Int>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -1017,7 +1017,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Double>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Double>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -1027,7 +1027,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Float>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, Float>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -1037,7 +1037,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSNumber>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
Select<TestEntity1, NSNumber>(.sum(#keyPath(TestEntity1.testNumber))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -1047,7 +1047,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDecimalNumber>(.sum(#keyPath(TestEntity1.testDecimal))),
|
||||
Select<TestEntity1, NSDecimalNumber>(.sum(#keyPath(TestEntity1.testDecimal))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -1057,7 +1057,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<String>(.sum(#keyPath(TestEntity1.testString))),
|
||||
Select<TestEntity1, String>(.sum(#keyPath(TestEntity1.testString))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1066,7 +1066,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSString>(.sum(#keyPath(TestEntity1.testString))),
|
||||
Select<TestEntity1, NSString>(.sum(#keyPath(TestEntity1.testString))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1075,7 +1075,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Data>(.sum(#keyPath(TestEntity1.testData))),
|
||||
Select<TestEntity1, Data>(.sum(#keyPath(TestEntity1.testData))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1084,7 +1084,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSData>(.sum(#keyPath(TestEntity1.testData))),
|
||||
Select<TestEntity1, NSData>(.sum(#keyPath(TestEntity1.testData))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1093,7 +1093,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Date>(.sum(#keyPath(TestEntity1.testDate))),
|
||||
Select<TestEntity1, Date>(.sum(#keyPath(TestEntity1.testDate))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1102,7 +1102,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDate>(.sum(#keyPath(TestEntity1.testDate))),
|
||||
Select<TestEntity1, NSDate>(.sum(#keyPath(TestEntity1.testDate))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1111,7 +1111,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSManagedObjectID>(.sum(#keyPath(TestEntity1.testEntityID))),
|
||||
Select<TestEntity1, NSManagedObjectID>(.sum(#keyPath(TestEntity1.testEntityID))),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1135,7 +1135,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Bool>(.objectID()),
|
||||
Select<TestEntity1, Bool>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1144,7 +1144,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int8>(.objectID()),
|
||||
Select<TestEntity1, Int8>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1153,7 +1153,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int16>(.objectID()),
|
||||
Select<TestEntity1, Int16>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1162,7 +1162,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int32>(.objectID()),
|
||||
Select<TestEntity1, Int32>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1171,7 +1171,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int64>(.objectID()),
|
||||
Select<TestEntity1, Int64>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1180,7 +1180,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Int>(.objectID()),
|
||||
Select<TestEntity1, Int>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1189,7 +1189,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Double>(.objectID()),
|
||||
Select<TestEntity1, Double>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1198,7 +1198,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Float>(.objectID()),
|
||||
Select<TestEntity1, Float>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1207,7 +1207,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSNumber>(.objectID()),
|
||||
Select<TestEntity1, NSNumber>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1216,7 +1216,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDecimalNumber>(.objectID()),
|
||||
Select<TestEntity1, NSDecimalNumber>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1225,7 +1225,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<String>(.objectID()),
|
||||
Select<TestEntity1, String>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1234,7 +1234,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSString>(.objectID()),
|
||||
Select<TestEntity1, NSString>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1243,7 +1243,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Data>(.objectID()),
|
||||
Select<TestEntity1, Data>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1252,7 +1252,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSData>(.objectID()),
|
||||
Select<TestEntity1, NSData>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1261,7 +1261,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<Date>(.objectID()),
|
||||
Select<TestEntity1, Date>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1270,7 +1270,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSDate>(.objectID()),
|
||||
Select<TestEntity1, NSDate>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNil(value)
|
||||
@@ -1279,7 +1279,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let value = stack.queryValue(
|
||||
from,
|
||||
Select<NSManagedObjectID>(.objectID()),
|
||||
Select<TestEntity1, NSManagedObjectID>(.objectID()),
|
||||
queryClauses
|
||||
)
|
||||
XCTAssertNotNil(value)
|
||||
@@ -1304,7 +1304,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let values = stack.queryAttributes(
|
||||
from,
|
||||
Select(
|
||||
Select<TestEntity1, NSDictionary>(
|
||||
#keyPath(TestEntity1.testBoolean),
|
||||
#keyPath(TestEntity1.testNumber),
|
||||
#keyPath(TestEntity1.testDecimal),
|
||||
@@ -1355,7 +1355,7 @@ class QueryTests: BaseTestDataTestCase {
|
||||
|
||||
let values = stack.queryAttributes(
|
||||
from,
|
||||
Select(
|
||||
Select<TestEntity1, NSDictionary>(
|
||||
.sum(#keyPath(TestEntity1.testBoolean)),
|
||||
.count(#keyPath(TestEntity1.testNumber)),
|
||||
.maximum(#keyPath(TestEntity1.testNumber)),
|
||||
|
||||
@@ -38,7 +38,7 @@ final class SelectTests: XCTestCase {
|
||||
|
||||
do {
|
||||
|
||||
let term: SelectTerm = "attribute"
|
||||
let term: SelectTerm<NSManagedObject> = "attribute"
|
||||
XCTAssertEqual(term, SelectTerm.attribute("attribute"))
|
||||
XCTAssertNotEqual(term, SelectTerm.attribute("attribute2"))
|
||||
XCTAssertNotEqual(term, SelectTerm.average("attribute"))
|
||||
@@ -58,7 +58,7 @@ final class SelectTests: XCTestCase {
|
||||
}
|
||||
do {
|
||||
|
||||
let term = SelectTerm.attribute("attribute")
|
||||
let term = SelectTerm<NSManagedObject>.attribute("attribute")
|
||||
XCTAssertNotEqual(term, SelectTerm.attribute("attribute2"))
|
||||
XCTAssertNotEqual(term, SelectTerm.average("attribute"))
|
||||
XCTAssertNotEqual(term, SelectTerm.count("attribute"))
|
||||
@@ -82,7 +82,7 @@ final class SelectTests: XCTestCase {
|
||||
|
||||
do {
|
||||
|
||||
let term = SelectTerm.average("attribute")
|
||||
let term = SelectTerm<NSManagedObject>.average("attribute")
|
||||
XCTAssertEqual(term, SelectTerm.average("attribute"))
|
||||
XCTAssertNotEqual(term, SelectTerm.average("attribute", as: "alias"))
|
||||
XCTAssertNotEqual(term, SelectTerm.average("attribute2"))
|
||||
@@ -106,7 +106,7 @@ final class SelectTests: XCTestCase {
|
||||
}
|
||||
do {
|
||||
|
||||
let term = SelectTerm.average("attribute", as: "alias")
|
||||
let term = SelectTerm<NSManagedObject>.average("attribute", as: "alias")
|
||||
XCTAssertEqual(term, SelectTerm.average("attribute", as: "alias"))
|
||||
XCTAssertNotEqual(term, SelectTerm.average("attribute", as: "alias2"))
|
||||
XCTAssertNotEqual(term, SelectTerm.average("attribute2"))
|
||||
@@ -135,7 +135,7 @@ final class SelectTests: XCTestCase {
|
||||
|
||||
do {
|
||||
|
||||
let term = SelectTerm.count("attribute")
|
||||
let term = SelectTerm<NSManagedObject>.count("attribute")
|
||||
XCTAssertEqual(term, SelectTerm.count("attribute"))
|
||||
XCTAssertNotEqual(term, SelectTerm.count("attribute", as: "alias"))
|
||||
XCTAssertNotEqual(term, SelectTerm.count("attribute2"))
|
||||
@@ -159,7 +159,7 @@ final class SelectTests: XCTestCase {
|
||||
}
|
||||
do {
|
||||
|
||||
let term = SelectTerm.count("attribute", as: "alias")
|
||||
let term = SelectTerm<NSManagedObject>.count("attribute", as: "alias")
|
||||
XCTAssertEqual(term, SelectTerm.count("attribute", as: "alias"))
|
||||
XCTAssertNotEqual(term, SelectTerm.count("attribute", as: "alias2"))
|
||||
XCTAssertNotEqual(term, SelectTerm.count("attribute2"))
|
||||
@@ -188,7 +188,7 @@ final class SelectTests: XCTestCase {
|
||||
|
||||
do {
|
||||
|
||||
let term = SelectTerm.maximum("attribute")
|
||||
let term = SelectTerm<NSManagedObject>.maximum("attribute")
|
||||
XCTAssertEqual(term, SelectTerm.maximum("attribute"))
|
||||
XCTAssertNotEqual(term, SelectTerm.maximum("attribute", as: "alias"))
|
||||
XCTAssertNotEqual(term, SelectTerm.maximum("attribute2"))
|
||||
@@ -212,7 +212,7 @@ final class SelectTests: XCTestCase {
|
||||
}
|
||||
do {
|
||||
|
||||
let term = SelectTerm.maximum("attribute", as: "alias")
|
||||
let term = SelectTerm<NSManagedObject>.maximum("attribute", as: "alias")
|
||||
XCTAssertEqual(term, SelectTerm.maximum("attribute", as: "alias"))
|
||||
XCTAssertNotEqual(term, SelectTerm.maximum("attribute", as: "alias2"))
|
||||
XCTAssertNotEqual(term, SelectTerm.maximum("attribute2"))
|
||||
@@ -241,7 +241,7 @@ final class SelectTests: XCTestCase {
|
||||
|
||||
do {
|
||||
|
||||
let term = SelectTerm.minimum("attribute")
|
||||
let term = SelectTerm<NSManagedObject>.minimum("attribute")
|
||||
XCTAssertEqual(term, SelectTerm.minimum("attribute"))
|
||||
XCTAssertNotEqual(term, SelectTerm.minimum("attribute", as: "alias"))
|
||||
XCTAssertNotEqual(term, SelectTerm.minimum("attribute2"))
|
||||
@@ -265,7 +265,7 @@ final class SelectTests: XCTestCase {
|
||||
}
|
||||
do {
|
||||
|
||||
let term = SelectTerm.minimum("attribute", as: "alias")
|
||||
let term = SelectTerm<NSManagedObject>.minimum("attribute", as: "alias")
|
||||
XCTAssertEqual(term, SelectTerm.minimum("attribute", as: "alias"))
|
||||
XCTAssertNotEqual(term, SelectTerm.minimum("attribute", as: "alias2"))
|
||||
XCTAssertNotEqual(term, SelectTerm.minimum("attribute2"))
|
||||
@@ -294,7 +294,7 @@ final class SelectTests: XCTestCase {
|
||||
|
||||
do {
|
||||
|
||||
let term = SelectTerm.sum("attribute")
|
||||
let term = SelectTerm<NSManagedObject>.sum("attribute")
|
||||
XCTAssertEqual(term, SelectTerm.sum("attribute"))
|
||||
XCTAssertNotEqual(term, SelectTerm.sum("attribute", as: "alias"))
|
||||
XCTAssertNotEqual(term, SelectTerm.sum("attribute2"))
|
||||
@@ -318,7 +318,7 @@ final class SelectTests: XCTestCase {
|
||||
}
|
||||
do {
|
||||
|
||||
let term = SelectTerm.sum("attribute", as: "alias")
|
||||
let term = SelectTerm<NSManagedObject>.sum("attribute", as: "alias")
|
||||
XCTAssertEqual(term, SelectTerm.sum("attribute", as: "alias"))
|
||||
XCTAssertNotEqual(term, SelectTerm.sum("attribute", as: "alias2"))
|
||||
XCTAssertNotEqual(term, SelectTerm.sum("attribute2"))
|
||||
@@ -347,7 +347,7 @@ final class SelectTests: XCTestCase {
|
||||
|
||||
do {
|
||||
|
||||
let term = SelectTerm.objectID()
|
||||
let term = SelectTerm<NSManagedObject>.objectID()
|
||||
XCTAssertEqual(term, SelectTerm.objectID())
|
||||
XCTAssertNotEqual(term, SelectTerm.objectID(as: "alias"))
|
||||
XCTAssertNotEqual(term, SelectTerm.attribute("attribute"))
|
||||
@@ -368,7 +368,7 @@ final class SelectTests: XCTestCase {
|
||||
}
|
||||
do {
|
||||
|
||||
let term = SelectTerm.objectID(as: "alias")
|
||||
let term = SelectTerm<NSManagedObject>.objectID(as: "alias")
|
||||
XCTAssertEqual(term, SelectTerm.objectID(as: "alias"))
|
||||
XCTAssertNotEqual(term, SelectTerm.objectID(as: "alias2"))
|
||||
XCTAssertNotEqual(term, SelectTerm.objectID())
|
||||
@@ -393,12 +393,12 @@ final class SelectTests: XCTestCase {
|
||||
@objc
|
||||
dynamic func test_ThatSelectClauses_ConfigureCorrectly() {
|
||||
|
||||
let term1 = SelectTerm.attribute("attribute1")
|
||||
let term2 = SelectTerm.attribute("attribute2")
|
||||
let term3 = SelectTerm.attribute("attribute3")
|
||||
let term1 = SelectTerm<NSManagedObject>.attribute("attribute1")
|
||||
let term2 = SelectTerm<NSManagedObject>.attribute("attribute2")
|
||||
let term3 = SelectTerm<NSManagedObject>.attribute("attribute3")
|
||||
do {
|
||||
|
||||
let select = Select<Int>(term1, term2, term3)
|
||||
let select = Select<NSManagedObject, Int>(term1, term2, term3)
|
||||
XCTAssertEqual(select.selectTerms, [term1, term2, term3])
|
||||
XCTAssertNotEqual(select.selectTerms, [term1, term3, term2])
|
||||
XCTAssertNotEqual(select.selectTerms, [term2, term1, term3])
|
||||
@@ -408,7 +408,7 @@ final class SelectTests: XCTestCase {
|
||||
}
|
||||
do {
|
||||
|
||||
let select = Select<Int>([term1, term2, term3])
|
||||
let select = Select<NSManagedObject, Int>([term1, term2, term3])
|
||||
XCTAssertEqual(select.selectTerms, [term1, term2, term3])
|
||||
XCTAssertNotEqual(select.selectTerms, [term1, term3, term2])
|
||||
XCTAssertNotEqual(select.selectTerms, [term2, term1, term3])
|
||||
|
||||
@@ -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.
|
||||
- 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(
|
||||
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.
|
||||
- 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(
|
||||
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.
|
||||
- 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(
|
||||
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.
|
||||
- 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(
|
||||
self.isRunningInAllowedQueue(),
|
||||
|
||||
@@ -35,7 +35,7 @@ import CoreData
|
||||
- SeeAlso: `SelectTerm`
|
||||
*/
|
||||
@objc
|
||||
public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
|
||||
public final class CSSelectTerm: NSObject {
|
||||
|
||||
/**
|
||||
Provides a `CSSelectTerm` to a `CSSelect` clause for querying an entity attribute.
|
||||
@@ -175,11 +175,11 @@ public final class CSSelectTerm: NSObject, 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()
|
||||
}
|
||||
}
|
||||
@@ -187,7 +187,7 @@ public final class CSSelectTerm: NSObject, CoreStoreObjectiveCType {
|
||||
|
||||
// MARK: - SelectTerm
|
||||
|
||||
extension SelectTerm: CoreStoreSwiftType {
|
||||
extension SelectTerm where D: NSManagedObject {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
@@ -195,6 +195,24 @@ extension SelectTerm: CoreStoreSwiftType {
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
public init<T: QueryableAttributeType>(_ swiftValue: Select<T>) {
|
||||
public init<D: NSManagedObject, T: QueryableAttributeType>(_ swiftValue: Select<D, T>) {
|
||||
|
||||
self.attributeType = T.cs_rawAttributeType
|
||||
self.selectTerms = swiftValue.selectTerms
|
||||
self.selectTerms = swiftValue.selectTerms.map({ $0.downcast() })
|
||||
self.bridgeToSwift = swiftValue
|
||||
super.init()
|
||||
}
|
||||
|
||||
public init<T>(_ swiftValue: Select<T>) {
|
||||
public init<D: NSManagedObject, T>(_ swiftValue: Select<D, T>) {
|
||||
|
||||
self.attributeType = .undefinedAttributeType
|
||||
self.selectTerms = swiftValue.selectTerms
|
||||
self.selectTerms = swiftValue.selectTerms.map({ $0.downcast() })
|
||||
self.bridgeToSwift = swiftValue
|
||||
super.init()
|
||||
}
|
||||
@@ -385,7 +403,95 @@ public final class CSSelect: NSObject {
|
||||
// MARK: Internal
|
||||
|
||||
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
|
||||
@@ -396,7 +502,7 @@ public final class CSSelect: NSObject {
|
||||
|
||||
// MARK: - Select
|
||||
|
||||
extension Select: CoreStoreSwiftType {
|
||||
extension Select where D: NSManagedObject {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
@@ -404,4 +510,12 @@ extension Select: CoreStoreSwiftType {
|
||||
|
||||
return CSSelect(self)
|
||||
}
|
||||
|
||||
|
||||
// MARK: FilePrivate
|
||||
|
||||
fileprivate func downcast() -> Select<NSManagedObject, T> {
|
||||
|
||||
return Select<NSManagedObject, T>(self.selectTerms.map({ $0.downcast() }))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public protocol QueryChainableBuilderType {
|
||||
associatedtype ResultType: SelectResultType
|
||||
|
||||
var from: From<ObjectType> { get set }
|
||||
var select: Select<ResultType> { get set }
|
||||
var select: Select<ObjectType, ResultType> { get set }
|
||||
var queryClauses: [QueryClause] { get set }
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public struct QueryChainBuilder<D: DynamicObject, R: SelectResultType>: QueryCha
|
||||
public typealias ResultType = R
|
||||
|
||||
public var from: From<D>
|
||||
public var select: Select<R>
|
||||
public var select: Select<D, R>
|
||||
public var queryClauses: [QueryClause] = []
|
||||
}
|
||||
|
||||
@@ -101,12 +101,12 @@ public struct SectionMonitorChainBuilder<D: DynamicObject>: SectionMonitorBuilde
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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(
|
||||
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 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, *)
|
||||
public extension SectionMonitorChainBuilder {
|
||||
|
||||
|
||||
@@ -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.
|
||||
- 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)
|
||||
}
|
||||
@@ -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.
|
||||
- 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)
|
||||
}
|
||||
@@ -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.
|
||||
- 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)
|
||||
}
|
||||
@@ -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.
|
||||
- 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)
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
- 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(
|
||||
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.
|
||||
- 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(
|
||||
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.
|
||||
- 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(
|
||||
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.
|
||||
- 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(
|
||||
Thread.isMainThread,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -142,15 +142,14 @@ internal extension NSManagedObjectContext {
|
||||
|
||||
fetchRequest.fetchLimit = 0
|
||||
|
||||
let selectTerms = selectClause.selectTerms
|
||||
selectTerms.applyToFetchRequest(fetchRequest, owner: selectClause)
|
||||
selectClause.applyToFetchRequest(fetchRequest)
|
||||
queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||
|
||||
guard storeFound else {
|
||||
|
||||
return nil
|
||||
}
|
||||
return self.queryValue(selectTerms, fetchRequest: fetchRequest.dynamicCast())
|
||||
return self.queryValue(selectClause.selectTerms, fetchRequest: fetchRequest.dynamicCast())
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
@@ -161,7 +160,7 @@ internal extension NSManagedObjectContext {
|
||||
|
||||
fetchRequest.fetchLimit = 0
|
||||
|
||||
selectClause.selectTerms.applyToFetchRequest(fetchRequest, owner: selectClause)
|
||||
selectClause.applyToFetchRequest(fetchRequest)
|
||||
queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||
|
||||
guard storeFound else {
|
||||
|
||||
@@ -279,51 +279,50 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
||||
// MARK: QueryableSource
|
||||
|
||||
@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)
|
||||
}
|
||||
|
||||
@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 storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||
|
||||
fetchRequest.fetchLimit = 0
|
||||
|
||||
let selectTerms = selectClause.selectTerms
|
||||
selectTerms.applyToFetchRequest(fetchRequest, owner: selectClause)
|
||||
selectClause.applyToFetchRequest(fetchRequest)
|
||||
queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||
|
||||
guard storeFound else {
|
||||
|
||||
return nil
|
||||
}
|
||||
return self.queryValue(selectTerms, fetchRequest: fetchRequest)
|
||||
return self.queryValue(selectClause.selectTerms, fetchRequest: fetchRequest)
|
||||
}
|
||||
|
||||
@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)
|
||||
}
|
||||
|
||||
@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)
|
||||
}
|
||||
|
||||
@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 storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||
|
||||
fetchRequest.fetchLimit = 0
|
||||
|
||||
selectClause.selectTerms.applyToFetchRequest(fetchRequest, owner: selectClause)
|
||||
selectClause.applyToFetchRequest(fetchRequest)
|
||||
queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||
|
||||
guard storeFound else {
|
||||
@@ -498,7 +497,7 @@ internal extension NSManagedObjectContext {
|
||||
// MARK: Querying
|
||||
|
||||
@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 fetchError: Error?
|
||||
@@ -516,9 +515,9 @@ internal extension NSManagedObjectContext {
|
||||
if let fetchResults = fetchResults {
|
||||
|
||||
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
|
||||
}
|
||||
@@ -531,7 +530,7 @@ internal extension NSManagedObjectContext {
|
||||
}
|
||||
|
||||
@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 fetchError: Error?
|
||||
@@ -549,7 +548,7 @@ internal extension NSManagedObjectContext {
|
||||
if let fetchResults = fetchResults {
|
||||
|
||||
if let rawResult = fetchResults.first as? NSDictionary,
|
||||
let rawObject = rawResult[selectTerms.keyPathForFirstSelectTerm()] {
|
||||
let rawObject = rawResult[selectTerms.first!.keyPathString] {
|
||||
|
||||
return rawObject
|
||||
}
|
||||
@@ -581,7 +580,7 @@ internal extension NSManagedObjectContext {
|
||||
}
|
||||
if let fetchResults = fetchResults {
|
||||
|
||||
return Select<NSDictionary>.ReturnType.cs_fromQueryResultsNativeType(fetchResults)
|
||||
return NSDictionary.cs_fromQueryResultsNativeType(fetchResults)
|
||||
}
|
||||
|
||||
CoreStore.log(
|
||||
|
||||
@@ -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.
|
||||
- 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.
|
||||
@@ -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.
|
||||
- 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
|
||||
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.
|
||||
- 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.
|
||||
@@ -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.
|
||||
- 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
|
||||
func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
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:
|
||||
@@ -74,7 +74,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
||||
- parameter keyPath: the attribute name
|
||||
- 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)
|
||||
}
|
||||
@@ -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
|
||||
- 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(
|
||||
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
|
||||
- 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(
|
||||
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
|
||||
- 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(
|
||||
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
|
||||
- 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(
|
||||
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
|
||||
- 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(
|
||||
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
|
||||
- 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(
|
||||
alias: alias ?? "objectID",
|
||||
@@ -231,7 +231,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
||||
|
||||
// MARK: Equatable
|
||||
|
||||
public static func == (lhs: SelectTerm, rhs: SelectTerm) -> Bool {
|
||||
public static func == (lhs: SelectTerm<D>, rhs: SelectTerm<D>) -> Bool {
|
||||
|
||||
switch (lhs, rhs) {
|
||||
|
||||
@@ -248,7 +248,9 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
||||
case (._identity(let alias1, let nativeType1), ._identity(let alias2, let nativeType2)):
|
||||
return alias1 == alias2 && nativeType1 == nativeType2
|
||||
|
||||
default:
|
||||
case (._attribute, _),
|
||||
(._aggregate, _),
|
||||
(._identity, _):
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -277,6 +279,355 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
||||
case _attribute(KeyPathString)
|
||||
case _aggregate(function: String, keyPath: KeyPathString, 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
|
||||
*/
|
||||
public struct Select<T: SelectResultType>: Hashable {
|
||||
|
||||
/**
|
||||
The `SelectResultType` type for the query's return value
|
||||
*/
|
||||
public typealias ReturnType = T
|
||||
public struct Select<D: DynamicObject, T: SelectResultType>: SelectClause, Hashable {
|
||||
|
||||
/**
|
||||
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 selectTerms: a series of `SelectTerm`s
|
||||
*/
|
||||
public init(_ selectTerm: SelectTerm, _ selectTerms: SelectTerm...) {
|
||||
public init(_ selectTerm: SelectTerm<D>, _ selectTerms: SelectTerm<D>...) {
|
||||
|
||||
self.selectTerms = [selectTerm] + selectTerms
|
||||
}
|
||||
@@ -331,7 +677,7 @@ public struct Select<T: SelectResultType>: Hashable {
|
||||
|
||||
- parameter selectTerms: a series of `SelectTerm`s
|
||||
*/
|
||||
public init(_ selectTerms: [SelectTerm]) {
|
||||
public init(_ selectTerms: [SelectTerm<D>]) {
|
||||
|
||||
self.selectTerms = selectTerms
|
||||
}
|
||||
@@ -339,12 +685,20 @@ public struct Select<T: SelectResultType>: Hashable {
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
|
||||
// MARK: SelectClause
|
||||
|
||||
public typealias ObjectType = D
|
||||
public typealias ReturnType = T
|
||||
|
||||
public let selectTerms: [SelectTerm<D>]
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
@@ -355,36 +709,7 @@ public struct Select<T: SelectResultType>: Hashable {
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
internal let selectTerms: [SelectTerm]
|
||||
}
|
||||
|
||||
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) {
|
||||
internal func applyToFetchRequest(_ fetchRequest: NSFetchRequest<NSFetchRequestResult>) {
|
||||
|
||||
fetchRequest.includesPendingChanges = false
|
||||
fetchRequest.resultType = .dictionaryResultType
|
||||
@@ -414,7 +739,7 @@ internal extension Collection where Iterator.Element == SelectTerm {
|
||||
}
|
||||
|
||||
var propertiesToFetch = [Any]()
|
||||
for term in self {
|
||||
for term in self.selectTerms {
|
||||
|
||||
switch term {
|
||||
|
||||
@@ -445,7 +770,7 @@ internal extension Collection where Iterator.Element == SelectTerm {
|
||||
|
||||
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(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
|
||||
}
|
||||
}
|
||||
|
||||
public extension Select where T: NSManagedObjectID {
|
||||
|
||||
internal func keyPathForFirstSelectTerm() -> KeyPathString {
|
||||
/**
|
||||
Initializes a `Select` that queries for `NSManagedObjectID` results
|
||||
*/
|
||||
public init() {
|
||||
|
||||
switch self.first! {
|
||||
|
||||
case ._attribute(let keyPath):
|
||||
return keyPath
|
||||
|
||||
case ._aggregate(_, _, let alias, _):
|
||||
return alias
|
||||
|
||||
case ._identity(let alias, _):
|
||||
return alias
|
||||
}
|
||||
self.init(.objectID())
|
||||
}
|
||||
}
|
||||
|
||||
public extension Select where D: NSManagedObject {
|
||||
|
||||
/**
|
||||
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]]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user