WIP: documentations

This commit is contained in:
John Rommel Estropia
2017-10-24 00:31:27 +09:00
parent e37186da73
commit b6ee0b014f
13 changed files with 444 additions and 54 deletions

View File

@@ -68,7 +68,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
/**
Deletes all `DynamicObject`s that satisfy the specified conditions.
```
transaction.deleteAll(From<Person>().where(\.age > 50)
transaction.deleteAll(From<Person>().where(\.age > 50))
```
- parameter clauseChain: a `FetchChainableBuilderType` clause chain created from a `From` clause
- returns: the number of `DynamicObject`s deleted
@@ -163,7 +163,18 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
return self.context.fetchOne(from, fetchClauses)
}
// TODO: docs
/**
Fetches the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let youngestTeen = transaction.fetchOne(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`
*/
public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) -> B.ObjectType? {
CoreStore.assert(
@@ -205,7 +216,18 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
return self.context.fetchAll(from, fetchClauses)
}
// TODO: docs
/**
Fetches all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let people = transaction.fetchAll(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`
*/
public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) -> [B.ObjectType]? {
CoreStore.assert(
@@ -247,7 +269,18 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
return self.context.fetchCount(from, fetchClauses)
}
// TODO: docs
/**
Fetches the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let numberOfAdults = transaction.fetchCount(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
*/
public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) -> Int? {
CoreStore.assert(
@@ -289,7 +322,18 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
return self.context.fetchObjectID(from, fetchClauses)
}
// TODO: docs
/**
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let youngestTeenID = transaction.fetchObjectID(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`
*/
public func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) -> NSManagedObjectID? {
CoreStore.assert(
@@ -331,7 +375,18 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
return self.context.fetchObjectIDs(from, fetchClauses)
}
// TODO: docs
/**
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let idsOfAdults = transaction.fetchObjectIDs(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
*/
public func fetchObjectIDs<B: FetchChainableBuilderType>(_ clauseChain: B) -> [NSManagedObjectID]? {
CoreStore.assert(
@@ -382,7 +437,20 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
return self.context.queryValue(from, selectClause, queryClauses)
}
// TODO: docs
/**
Queries a property value or aggregate as specified by the `QueryChainableBuilderType` built from a chain of clauses.
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
```
let averageAdultAge = transaction.queryValue(
From<MyPersonEntity>()
.select(Int.self, .average(\.age))
.where(\.age > 18)
)
```
- parameter clauseChain: a `QueryChainableBuilderType` indicating the property/aggregate to fetch and the series of queries for the request.
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
*/
public func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType {
CoreStore.assert(
@@ -430,7 +498,29 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
return self.context.queryAttributes(from, selectClause, queryClauses)
}
// TODO: docs
/**
Queries a dictionary of attribute values or as specified by the `QueryChainableBuilderType` built from a chain of clauses.
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
```
let results = dataStack.queryAttributes(
From<MyPersonEntity>()
.select(
NSDictionary.self,
.attribute(\.age, as: "age"),
.count(\.age, as: "numberOfPeople")
)
.groupBy(\.age)
)
for dictionary in results! {
let age = dictionary["age"] as! Int
let count = dictionary["numberOfPeople"] as! Int
print("There are \(count) people who are \(age) years old."
}
```
- parameter clauseChain: a `QueryChainableBuilderType` indicating the properties to fetch and the series of queries for the request.
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
*/
public func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary {
CoreStore.assert(

View File

@@ -116,10 +116,10 @@ public /*abstract*/ class BaseDataTransaction {
}
/**
Returns an editable proxy of a specified `NSManagedObject`.
Returns an editable proxy of a specified `NSManagedObject` or `CoreStoreObject`.
- parameter object: the `NSManagedObject` type to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
- parameter object: the `NSManagedObject` or `CoreStoreObject` type to be edited
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
*/
public func edit<D: DynamicObject>(_ object: D?) -> D? {
@@ -139,7 +139,7 @@ public /*abstract*/ class BaseDataTransaction {
- parameter into: an `Into` clause specifying the entity type
- parameter objectID: the `NSManagedObjectID` for the object to be edited
- returns: an editable proxy for the specified `NSManagedObject`.
- returns: an editable proxy for the specified `NSManagedObject` or `CoreStoreObject`.
*/
public func edit<D>(_ into: Into<D>, _ objectID: NSManagedObjectID) -> D? {
@@ -156,9 +156,9 @@ public /*abstract*/ class BaseDataTransaction {
}
/**
Deletes a specified `NSManagedObject`.
Deletes a specified `NSManagedObject` or `CoreStoreObject`.
- parameter object: the `NSManagedObject` to be deleted
- parameter object: the `NSManagedObject` or `CoreStoreObject` to be deleted
*/
public func delete<D: DynamicObject>(_ object: D?) {
@@ -173,11 +173,11 @@ public /*abstract*/ class BaseDataTransaction {
}
/**
Deletes the specified `NSManagedObject`s.
Deletes the specified `NSManagedObject`s or `CoreStoreObject`s.
- parameter object1: the `NSManagedObject` to be deleted
- parameter object2: another `NSManagedObject` to be deleted
- parameter objects: other `NSManagedObject`s to be deleted
- parameter object1: the `NSManagedObject` or `CoreStoreObject` to be deleted
- parameter object2: another `NSManagedObject` or `CoreStoreObject` to be deleted
- parameter objects: other `NSManagedObject`s or `CoreStoreObject`s to be deleted
*/
public func delete<D: DynamicObject>(_ object1: D?, _ object2: D?, _ objects: D?...) {
@@ -185,9 +185,9 @@ public /*abstract*/ class BaseDataTransaction {
}
/**
Deletes the specified `NSManagedObject`s.
Deletes the specified `NSManagedObject`s or `CoreStoreObject`s.
- parameter objects: the `NSManagedObject`s to be deleted
- parameter objects: the `NSManagedObject`s or `CoreStoreObject`s to be deleted
*/
public func delete<S: Sequence>(_ objects: S) where S.Iterator.Element: DynamicObject {

View File

@@ -27,6 +27,8 @@ import Foundation
import CoreData
// MARK: - FetchChainableBuilderType
public protocol FetchChainableBuilderType {
associatedtype ObjectType: DynamicObject
@@ -35,6 +37,9 @@ public protocol FetchChainableBuilderType {
var fetchClauses: [FetchClause] { get set }
}
// MARK: - QueryChainableBuilderType
public protocol QueryChainableBuilderType {
associatedtype ObjectType: DynamicObject

View File

@@ -99,7 +99,18 @@ public extension CoreStore {
return self.defaultStack.fetchOne(from, fetchClauses)
}
// TODO: docs
/**
Fetches the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let youngestTeen = CoreStore.fetchOne(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`
*/
public static func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) -> B.ObjectType? {
return self.defaultStack.fetchOne(clauseChain)
@@ -129,7 +140,18 @@ public extension CoreStore {
return self.defaultStack.fetchAll(from, fetchClauses)
}
// TODO: docs
/**
Fetches all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let people = CoreStore.fetchAll(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`
*/
public static func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) -> [B.ObjectType]? {
return self.defaultStack.fetchAll(clauseChain)
@@ -159,7 +181,18 @@ public extension CoreStore {
return self.defaultStack.fetchCount(from, fetchClauses)
}
// TODO: docs
/**
Fetches the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let numberOfAdults = CoreStore.fetchCount(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
*/
public static func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) -> Int? {
return self.defaultStack.fetchCount(clauseChain)
@@ -189,7 +222,18 @@ public extension CoreStore {
return self.defaultStack.fetchObjectID(from, fetchClauses)
}
// TODO: docs
/**
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let youngestTeenID = CoreStore.fetchObjectID(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`
*/
public static func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) -> NSManagedObjectID? {
return self.defaultStack.fetchObjectID(clauseChain)
@@ -219,7 +263,18 @@ public extension CoreStore {
return self.defaultStack.fetchObjectIDs(from, fetchClauses)
}
// TODO: docs
/**
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let idsOfAdults = transaction.fetchObjectIDs(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
*/
public static func fetchObjectIDs<B: FetchChainableBuilderType>(_ clauseChain: B) -> [NSManagedObjectID]? {
return self.defaultStack.fetchObjectIDs(clauseChain)
@@ -255,7 +310,20 @@ public extension CoreStore {
return self.defaultStack.queryValue(from, selectClause, queryClauses)
}
// TODO: docs
/**
Queries a property value or aggregate as specified by the `QueryChainableBuilderType` built from a chain of clauses.
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
```
let averageAdultAge = CoreStore.queryValue(
From<MyPersonEntity>()
.select(Int.self, .average(\.age))
.where(\.age > 18)
)
```
- parameter clauseChain: a `QueryChainableBuilderType` indicating the property/aggregate to fetch and the series of queries for the request.
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
*/
public static func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType {
return self.defaultStack.queryValue(clauseChain)
@@ -291,7 +359,29 @@ public extension CoreStore {
return self.defaultStack.queryAttributes(from, selectClause, queryClauses)
}
// TODO: docs
/**
Queries a dictionary of attribute values or as specified by the `QueryChainableBuilderType` built from a chain of clauses.
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
```
let results = CoreStore.queryAttributes(
From<MyPersonEntity>()
.select(
NSDictionary.self,
.attribute(\.age, as: "age"),
.count(\.age, as: "numberOfPeople")
)
.groupBy(\.age)
)
for dictionary in results! {
let age = dictionary["age"] as! Int
let count = dictionary["numberOfPeople"] as! Int
print("There are \(count) people who are \(age) years old."
}
```
- parameter clauseChain: a `QueryChainableBuilderType` indicating the properties to fetch and the series of queries for the request.
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
*/
public static func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary {
return self.defaultStack.queryAttributes(clauseChain)

View File

@@ -109,7 +109,18 @@ extension DataStack: FetchableSource, QueryableSource {
return self.mainContext.fetchOne(from, fetchClauses)
}
// TODO: docs
/**
Fetches the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let youngestTeen = dataStack.fetchOne(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`
*/
public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) -> B.ObjectType? {
CoreStore.assert(
@@ -151,7 +162,18 @@ extension DataStack: FetchableSource, QueryableSource {
return self.mainContext.fetchAll(from, fetchClauses)
}
// TODO: docs
/**
Fetches all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let people = dataStack.fetchAll(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`
*/
public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) -> [B.ObjectType]? {
CoreStore.assert(
@@ -193,7 +215,18 @@ extension DataStack: FetchableSource, QueryableSource {
return self.mainContext.fetchCount(from, fetchClauses)
}
// TODO: docs
/**
Fetches the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let numberOfAdults = dataStack.fetchCount(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
*/
public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) -> Int? {
CoreStore.assert(
@@ -235,7 +268,18 @@ extension DataStack: FetchableSource, QueryableSource {
return self.mainContext.fetchObjectID(from, fetchClauses)
}
// TODO: docs
/**
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let youngestTeenID = dataStack.fetchObjectID(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`
*/
public func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) -> NSManagedObjectID? {
CoreStore.assert(
@@ -277,7 +321,18 @@ extension DataStack: FetchableSource, QueryableSource {
return self.mainContext.fetchObjectIDs(from, fetchClauses)
}
// TODO: docs
/**
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let idsOfAdults = dataStack.fetchObjectIDs(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
*/
public func fetchObjectIDs<B: FetchChainableBuilderType>(_ clauseChain: B) -> [NSManagedObjectID]? {
CoreStore.assert(
@@ -328,7 +383,20 @@ extension DataStack: FetchableSource, QueryableSource {
return self.mainContext.queryValue(from, selectClause, queryClauses)
}
// TODO: docs
/**
Queries a property value or aggregate as specified by the `QueryChainableBuilderType` built from a chain of clauses.
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
```
let averageAdultAge = dataStack.queryValue(
From<MyPersonEntity>()
.select(Int.self, .average(\.age))
.where(\.age > 18)
)
```
- parameter clauseChain: a `QueryChainableBuilderType` indicating the property/aggregate to fetch and the series of queries for the request.
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
*/
public func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType {
CoreStore.assert(
@@ -376,7 +444,29 @@ extension DataStack: FetchableSource, QueryableSource {
return self.mainContext.queryAttributes(from, selectClause, queryClauses)
}
// TODO: docs
/**
Queries a dictionary of attribute values or as specified by the `QueryChainableBuilderType` built from a chain of clauses.
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
```
let results = dataStack.queryAttributes(
From<MyPersonEntity>()
.select(
NSDictionary.self,
.attribute(\.age, as: "age"),
.count(\.age, as: "numberOfPeople")
)
.groupBy(\.age)
)
for dictionary in results! {
let age = dictionary["age"] as! Int
let count = dictionary["numberOfPeople"] as! Int
print("There are \(count) people who are \(age) years old."
}
```
- parameter clauseChain: a `QueryChainableBuilderType` indicating the properties to fetch and the series of queries for the request.
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
*/
public func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary {
CoreStore.assert(

View File

@@ -84,7 +84,18 @@ public protocol FetchableSource: class {
*/
func fetchOne<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> D?
// TODO: docs
/**
Fetches the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let youngestTeen = source.fetchOne(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the first `DynamicObject` instance that satisfies the specified `FetchChainableBuilderType`
*/
func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) -> B.ObjectType?
/**
@@ -105,7 +116,18 @@ public protocol FetchableSource: class {
*/
func fetchAll<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [D]?
// TODO: docs
/**
Fetches all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let people = source.fetchAll(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: all `DynamicObject` instances that satisfy the specified `FetchChainableBuilderType`
*/
func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) -> [B.ObjectType]?
/**
@@ -126,7 +148,18 @@ public protocol FetchableSource: class {
*/
func fetchCount<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> Int?
// TODO: docs
/**
Fetches the number of `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let numberOfAdults = source.fetchCount(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the number `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
*/
func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) -> Int?
/**
@@ -147,7 +180,18 @@ public protocol FetchableSource: class {
*/
func fetchObjectID<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> NSManagedObjectID?
// TODO: docs
/**
Fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let youngestTeenID = source.fetchObjectID(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchChainableBuilderType`
*/
func fetchObjectID<B: FetchChainableBuilderType>(_ clauseChain: B) -> NSManagedObjectID?
/**
@@ -168,7 +212,18 @@ public protocol FetchableSource: class {
*/
func fetchObjectIDs<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> [NSManagedObjectID]?
// TODO: docs
/**
Fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType` built from a chain of clauses.
```
let idsOfAdults = source.fetchObjectIDs(
From<MyPersonEntity>()
.where(\.age > 18)
.orderBy(.ascending(\.age))
)
```
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchChainableBuilderType`
*/
func fetchObjectIDs<B: FetchChainableBuilderType>(_ clauseChain: B) -> [NSManagedObjectID]?
/**

View File

@@ -163,12 +163,18 @@ extension UUID: ImportableAttributeType {}
extension RawRepresentable where RawValue: ImportableAttributeType {
/**
Creates an instance of this type from its `QueryableNativeType` value.
*/
@inline(__always)
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
return RawValue.cs_fromQueryableNativeType(value).flatMap({ self.init(rawValue: $0) })
}
/**
Creates `QueryableNativeType` value from this instance.
*/
@inline(__always)
public func cs_toQueryableNativeType() -> QueryableNativeType {

View File

@@ -64,11 +64,11 @@ public struct Into<D: DynamicObject>: Hashable {
}
/**
Initializes an `Into` clause with the specified entity type.
Initializes an `Into` clause with the specified entity type. This is useful for querying a subclass while binding the generic type with a base class.
```
let person = transaction.create(Into(MyPersonEntity.self))
let person = transaction.create(Into<MyPersonEntity>(MyEmployeeEntity.self))
```
- parameter entity: the `NSManagedObject` type to be created
- parameter entity: the `NSManagedObject` or `CoreStoreObject` type to be created
*/
public init(_ entity: D.Type) {
@@ -80,7 +80,7 @@ public struct Into<D: DynamicObject>: Hashable {
```
let person = transaction.create(Into<MyPersonEntity>("Configuration1"))
```
- parameter configuration: the `NSPersistentStore` configuration name to associate the object to. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration.
- parameter configuration: the `NSPersistentStore` configuration name to associate the object to. This parameter is required if multiple configurations contain the created `NSManagedObject`'s or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
*/
public init(_ configuration: ModelConfiguration) {
@@ -88,12 +88,12 @@ public struct Into<D: DynamicObject>: Hashable {
}
/**
Initializes an `Into` clause with the specified entity type and configuration.
Initializes an `Into` clause with the specified entity type and configuration. This is useful for querying a subclass while binding the generic type with a base class.
```
let person = transaction.create(Into(MyPersonEntity.self, "Configuration1"))
let person = transaction.create(Into<MyPersonEntity>(MyEmployeeEntity.self, "Configuration1"))
```
- parameter entity: the `NSManagedObject` type to be created
- parameter configuration: the `NSPersistentStore` configuration name to associate the object to. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration.
- parameter entity: the `NSManagedObject` or `CoreStoreObject` type to be created
- parameter configuration: the `NSPersistentStore` configuration name to associate the object to. This parameter is required if multiple configurations contain the created `NSManagedObject`'s or `CoreStoreObject`'s entity type. Set to `nil` to use the default configuration.
*/
public init(_ entity: D.Type, _ configuration: ModelConfiguration) {

View File

@@ -123,7 +123,6 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
return self.fetchOne(fetchRequest.dynamicCast()).flatMap(from.entityClass.cs_fromRaw)
}
// TODO: docs
@nonobjc
public func fetchOne<B: FetchChainableBuilderType>(_ clauseChain: B) -> B.ObjectType? {
@@ -154,7 +153,6 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
return self.fetchAll(fetchRequest.dynamicCast())?.map(entityClass.cs_fromRaw)
}
// TODO: docs
@nonobjc
public func fetchAll<B: FetchChainableBuilderType>(_ clauseChain: B) -> [B.ObjectType]? {
@@ -181,7 +179,6 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
return self.fetchCount(fetchRequest.dynamicCast())
}
// TODO: docs
@nonobjc
public func fetchCount<B: FetchChainableBuilderType>(_ clauseChain: B) -> Int? {

View File

@@ -58,7 +58,20 @@ public protocol QueryableSource: class {
*/
func queryValue<D, U: QueryableAttributeType>(_ from: From<D>, _ selectClause: Select<D, U>, _ queryClauses: [QueryClause]) -> U?
// TODO: docs
/**
Queries a property value or aggregate as specified by the `QueryChainableBuilderType` built from a chain of clauses.
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
```
let averageAdultAge = dataStack.queryValue(
From<MyPersonEntity>()
.select(Int.self, .average(\.age))
.where(\.age > 18)
)
```
- parameter clauseChain: a `QueryChainableBuilderType` indicating the property/aggregate to fetch and the series of queries for the request.
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
*/
func queryValue<B: QueryChainableBuilderType>(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType
/**
@@ -85,7 +98,29 @@ public protocol QueryableSource: class {
*/
func queryAttributes<D>(_ from: From<D>, _ selectClause: Select<D, NSDictionary>, _ queryClauses: [QueryClause]) -> [[String: Any]]?
// TODO: docs
/**
Queries a dictionary of attribute values or as specified by the `QueryChainableBuilderType` built from a chain of clauses.
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
```
let results = source.queryAttributes(
From<MyPersonEntity>()
.select(
NSDictionary.self,
.attribute(\.age, as: "age"),
.count(\.age, as: "numberOfPeople")
)
.groupBy(\.age)
)
for dictionary in results! {
let age = dictionary["age"] as! Int
let count = dictionary["numberOfPeople"] as! Int
print("There are \(count) people who are \(age) years old."
}
```
- parameter clauseChain: a `QueryChainableBuilderType` indicating the properties to fetch and the series of queries for the request.
- returns: the result of the the query as specified by the `QueryChainableBuilderType`
*/
func queryAttributes<B: QueryChainableBuilderType>(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary
/**

View File

@@ -234,6 +234,9 @@ public enum RelationshipContainer<O: CoreStoreObject> {
// MARK: RelationshipProtocol
/**
The keyPath string represented by this property. Generally, there are more type-safe utilities for querying and other common tasks.
*/
public let keyPath: KeyPathString
internal let isToMany = false
@@ -502,6 +505,9 @@ public enum RelationshipContainer<O: CoreStoreObject> {
// MARK: RelationshipProtocol
/**
The keyPath string represented by this property. Generally, there are more type-safe utilities for querying and other common tasks.
*/
public let keyPath: KeyPathString
internal let isToMany = true
@@ -776,6 +782,9 @@ public enum RelationshipContainer<O: CoreStoreObject> {
// MARK: RelationshipProtocol
/**
The keyPath string represented by this property. Generally, there are more type-safe utilities for querying and other common tasks.
*/
public let keyPath: KeyPathString
internal let isToMany = true

View File

@@ -191,14 +191,17 @@ public enum TransformableContainer<O: CoreStoreObject> {
// MARK: AttributeProtocol
/**
The keyPath string represented by this property. Generally, there are more type-safe utilities for querying and other common tasks.
*/
public let keyPath: KeyPathString
internal static var attributeType: NSAttributeType {
return .transformableAttributeType
}
public let keyPath: KeyPathString
internal let isOptional = false
internal let isIndexed: Bool
internal let isTransient: Bool
@@ -420,6 +423,9 @@ public enum TransformableContainer<O: CoreStoreObject> {
return .transformableAttributeType
}
/**
The keyPath string represented by this property. Generally, there are more type-safe utilities for querying and other common tasks.
*/
public let keyPath: KeyPathString
internal let isOptional = true

View File

@@ -195,6 +195,9 @@ public enum ValueContainer<O: CoreStoreObject> {
return V.cs_rawAttributeType
}
/**
The keyPath string represented by this property. Generally, there are more type-safe utilities for querying and other common tasks.
*/
public let keyPath: KeyPathString
internal let isOptional = false
@@ -421,7 +424,11 @@ public enum ValueContainer<O: CoreStoreObject> {
return V.cs_rawAttributeType
}
/**
The keyPath string represented by this property. Generally, there are more type-safe utilities for querying and other common tasks.
*/
public let keyPath: KeyPathString
internal let isOptional = true
internal let isIndexed: Bool
internal let isTransient: Bool