mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-15 05:33:31 +01:00
WIP: chained queries for section monitors
This commit is contained in:
@@ -1392,9 +1392,9 @@
|
||||
B5E84F061AFF847B0064E85B /* DataStack+Querying.swift */,
|
||||
B5E84F071AFF847B0064E85B /* CoreStore+Querying.swift */,
|
||||
B596BBB51DD5BC67001DCDD9 /* FetchableSource.swift */,
|
||||
B55514E91EED8BF900BAB888 /* ChainedClauseBuilder.swift */,
|
||||
B596BBBA1DD5C39F001DCDD9 /* QueryableSource.swift */,
|
||||
B549F65D1E569C7400FBAB2D /* QueryableAttributeType.swift */,
|
||||
B55514E91EED8BF900BAB888 /* ChainedClauseBuilder.swift */,
|
||||
B5A1DAC61F111BBE003CF369 /* KeyPath Utilities */,
|
||||
B5E84F0A1AFF847B0064E85B /* Protocol Clauses */,
|
||||
B5E84EFF1AFF847B0064E85B /* Concrete Clauses */,
|
||||
|
||||
@@ -382,6 +382,16 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
||||
return self.context.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
// TODO: docs
|
||||
public func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to query from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.context.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
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.
|
||||
|
||||
@@ -420,6 +430,16 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
||||
return self.context.queryAttributes(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
// TODO: docs
|
||||
public func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
"Attempted to query from a \(cs_typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.context.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses)
|
||||
}
|
||||
|
||||
|
||||
// MARK: FetchableSource, QueryableSource
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public protocol QueryChainableBuilderType {
|
||||
var from: From<ObjectType> { get set }
|
||||
var select: Select<ResultType> { get set }
|
||||
var groupBy: GroupBy { get set }
|
||||
var fetchClauses: [FetchClause] { get set }
|
||||
var queryClauses: [QueryClause] { get set }
|
||||
}
|
||||
|
||||
public protocol SectionMonitorBuilderType {
|
||||
@@ -81,7 +81,7 @@ public struct QueryChainBuilder<D: DynamicObject, R: SelectResultType>: QueryCha
|
||||
public var from: From<D>
|
||||
public var select: Select<R>
|
||||
public var groupBy: GroupBy
|
||||
public var fetchClauses: [FetchClause] = []
|
||||
public var queryClauses: [QueryClause] = []
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ public extension From {
|
||||
from: self,
|
||||
select: .init(selectTerms),
|
||||
groupBy: .init(),
|
||||
fetchClauses: []
|
||||
queryClauses: []
|
||||
)
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ public extension QueryChainBuilder {
|
||||
from: self.from,
|
||||
select: self.select,
|
||||
groupBy: .init(keyPaths),
|
||||
fetchClauses: self.fetchClauses
|
||||
queryClauses: self.queryClauses
|
||||
)
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ public extension QueryChainBuilder {
|
||||
return self.queryChain(appending: Tweak(fetchRequest))
|
||||
}
|
||||
|
||||
public func appending(_ clause: FetchClause) -> QueryChainBuilder<D, R> {
|
||||
public func appending(_ clause: QueryClause) -> QueryChainBuilder<D, R> {
|
||||
|
||||
return self.queryChain(appending: clause)
|
||||
}
|
||||
@@ -263,13 +263,13 @@ public extension QueryChainBuilder {
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private func queryChain(appending clause: FetchClause) -> QueryChainBuilder<D, R> {
|
||||
private func queryChain(appending clause: QueryClause) -> QueryChainBuilder<D, R> {
|
||||
|
||||
return .init(
|
||||
from: self.from,
|
||||
select: self.select,
|
||||
groupBy: self.groupBy,
|
||||
fetchClauses: self.fetchClauses + [clause]
|
||||
queryClauses: self.queryClauses + [clause]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,6 +328,16 @@ extension DataStack: FetchableSource, QueryableSource {
|
||||
return self.mainContext.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
// TODO: docs
|
||||
public func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType {
|
||||
|
||||
CoreStore.assert(
|
||||
Thread.isMainThread,
|
||||
"Attempted to query from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.queryValue(clauseChain.from, clauseChain.select, clauseChain.queryClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
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.
|
||||
|
||||
@@ -366,6 +376,16 @@ extension DataStack: FetchableSource, QueryableSource {
|
||||
return self.mainContext.queryAttributes(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
// TODO: docs
|
||||
public func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary {
|
||||
|
||||
CoreStore.assert(
|
||||
Thread.isMainThread,
|
||||
"Attempted to query from a \(cs_typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.mainContext.queryAttributes(clauseChain.from, clauseChain.select, clauseChain.queryClauses)
|
||||
}
|
||||
|
||||
|
||||
// MARK: FetchableSource, QueryableSource
|
||||
|
||||
|
||||
@@ -57,6 +57,9 @@ public protocol QueryableSource: class {
|
||||
- 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?
|
||||
|
||||
// TODO: docs
|
||||
func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType
|
||||
|
||||
/**
|
||||
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.
|
||||
@@ -82,6 +85,9 @@ public protocol QueryableSource: class {
|
||||
*/
|
||||
func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]?
|
||||
|
||||
// TODO: docs
|
||||
func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary
|
||||
|
||||
/**
|
||||
The internal `NSManagedObjectContext` managed by this `QueryableSource`. Using this context directly should typically be avoided, and is provided by CoreStore only for extremely specialized cases.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user