mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-04-19 23:41:20 +02:00
WIP: demo app
This commit is contained in:
@@ -68,7 +68,6 @@ public struct From<T: NSManagedObject> {
|
||||
```
|
||||
let people = transaction.fetchAll(From<MyPersonEntity>())
|
||||
```
|
||||
|
||||
- parameter entity: the associated `NSManagedObject` type
|
||||
*/
|
||||
public init(_ entity: T.Type) {
|
||||
@@ -81,7 +80,6 @@ public struct From<T: NSManagedObject> {
|
||||
```
|
||||
let people = transaction.fetchAll(From<MyPersonEntity>())
|
||||
```
|
||||
|
||||
- parameter entityClass: the associated `NSManagedObject` entity class
|
||||
*/
|
||||
public init(_ entityClass: AnyClass) {
|
||||
@@ -98,7 +96,6 @@ public struct From<T: NSManagedObject> {
|
||||
```
|
||||
let people = transaction.fetchAll(From<MyPersonEntity>(nil, "Configuration1"))
|
||||
```
|
||||
|
||||
- parameter configuration: the `NSPersistentStore` configuration name to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration.
|
||||
- parameter otherConfigurations: an optional list of other configuration names to associate objects from (see `configuration` parameter)
|
||||
*/
|
||||
@@ -112,7 +109,6 @@ public struct From<T: NSManagedObject> {
|
||||
```
|
||||
let people = transaction.fetchAll(From<MyPersonEntity>(["Configuration1", "Configuration2"]))
|
||||
```
|
||||
|
||||
- parameter configurations: a list of `NSPersistentStore` configuration names to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration.
|
||||
*/
|
||||
public init(_ configurations: [String?]) {
|
||||
@@ -125,7 +121,6 @@ public struct From<T: NSManagedObject> {
|
||||
```
|
||||
let people = transaction.fetchAll(From(MyPersonEntity.self, nil, "Configuration1"))
|
||||
```
|
||||
|
||||
- parameter entity: the associated `NSManagedObject` type
|
||||
- parameter configuration: the `NSPersistentStore` configuration name to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration.
|
||||
- parameter otherConfigurations: an optional list of other configuration names to associate objects from (see `configuration` parameter)
|
||||
@@ -140,7 +135,6 @@ public struct From<T: NSManagedObject> {
|
||||
```
|
||||
let people = transaction.fetchAll(From(MyPersonEntity.self, ["Configuration1", "Configuration1"]))
|
||||
```
|
||||
|
||||
- parameter entity: the associated `NSManagedObject` type
|
||||
- parameter configurations: a list of `NSPersistentStore` configuration names to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration.
|
||||
*/
|
||||
@@ -154,7 +148,6 @@ public struct From<T: NSManagedObject> {
|
||||
```
|
||||
let people = transaction.fetchAll(From(MyPersonEntity.self, nil, "Configuration1"))
|
||||
```
|
||||
|
||||
- parameter entity: the associated `NSManagedObject` entity class
|
||||
- parameter configuration: the `NSPersistentStore` configuration name to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration.
|
||||
- parameter otherConfigurations: an optional list of other configuration names to associate objects from (see `configuration` parameter)
|
||||
@@ -173,7 +166,6 @@ public struct From<T: NSManagedObject> {
|
||||
```
|
||||
let people = transaction.fetchAll(From(MyPersonEntity.self, ["Configuration1", "Configuration1"]))
|
||||
```
|
||||
|
||||
- parameter entity: the associated `NSManagedObject` entity class
|
||||
- parameter configurations: a list of `NSPersistentStore` configuration names to associate objects from. This parameter is required if multiple configurations contain the created `NSManagedObject`'s entity type. Set to `nil` to use the default configuration.
|
||||
*/
|
||||
|
||||
@@ -73,7 +73,7 @@ public struct GroupBy: QueryClause, Hashable {
|
||||
|
||||
public func applyToFetchRequest<ResultType: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<ResultType>) {
|
||||
|
||||
if let keyPaths = fetchRequest.propertiesToGroupBy as? [String] where keyPaths != self.keyPaths {
|
||||
if let keyPaths = fetchRequest.propertiesToGroupBy as? [String], keyPaths != self.keyPaths {
|
||||
|
||||
CoreStore.log(
|
||||
.warning,
|
||||
|
||||
@@ -140,7 +140,7 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
|
||||
public func applyToFetchRequest<ResultType: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<ResultType>) {
|
||||
|
||||
if let sortDescriptors = fetchRequest.sortDescriptors where sortDescriptors != self.sortDescriptors {
|
||||
if let sortDescriptors = fetchRequest.sortDescriptors, sortDescriptors != self.sortDescriptors {
|
||||
|
||||
CoreStore.log(
|
||||
.warning,
|
||||
|
||||
@@ -83,7 +83,6 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Where("employeeID", isEqualTo: 1111)
|
||||
)
|
||||
```
|
||||
|
||||
- parameter keyPath: the attribute name
|
||||
- returns: a `SelectTerm` to a `Select` clause for querying an entity attribute
|
||||
*/
|
||||
@@ -100,7 +99,6 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Select<Int>(.average("age"))
|
||||
)
|
||||
```
|
||||
|
||||
- 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
|
||||
@@ -123,7 +121,6 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Select<Int>(.count("employeeID"))
|
||||
)
|
||||
```
|
||||
|
||||
- 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
|
||||
@@ -146,7 +143,6 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Select<Int>(.maximum("age"))
|
||||
)
|
||||
```
|
||||
|
||||
- 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
|
||||
@@ -169,7 +165,6 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Select<Int>(.minimum("age"))
|
||||
)
|
||||
```
|
||||
|
||||
- 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
|
||||
@@ -192,7 +187,6 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Select<Int>(.sum("age"))
|
||||
)
|
||||
```
|
||||
|
||||
- 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
|
||||
@@ -216,7 +210,6 @@ public enum SelectTerm: StringLiteralConvertible, Hashable {
|
||||
Where("employeeID", isEqualTo: 1111)
|
||||
)
|
||||
```
|
||||
|
||||
- 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 "objecID" is used
|
||||
- returns: a `SelectTerm` to a `Select` clause for querying the sum value for an attribute
|
||||
@@ -745,9 +738,9 @@ internal extension Collection where Iterator.Element == SelectTerm {
|
||||
fetchRequest.includesPendingChanges = false
|
||||
fetchRequest.resultType = .dictionaryResultType
|
||||
|
||||
func attributeDescriptionForKeyPath(keyPath: String, inEntity entity: NSEntityDescription) -> NSAttributeDescription? {
|
||||
func attributeDescription(for keyPath: String, in entity: NSEntityDescription) -> NSAttributeDescription? {
|
||||
|
||||
let components = keyPath.componentsSeparatedByString(".")
|
||||
let components = keyPath.components(separatedBy: ".")
|
||||
switch components.count {
|
||||
|
||||
case 0:
|
||||
@@ -761,9 +754,9 @@ internal extension Collection where Iterator.Element == SelectTerm {
|
||||
|
||||
return nil
|
||||
}
|
||||
return attributeDescriptionForKeyPath(
|
||||
components.dropFirst().joinWithSeparator("."),
|
||||
inEntity: relationship.entity
|
||||
return attributeDescription(
|
||||
for: components.dropFirst().joined(separator: "."),
|
||||
in: relationship.entity
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -775,7 +768,7 @@ internal extension Collection where Iterator.Element == SelectTerm {
|
||||
|
||||
case ._attribute(let keyPath):
|
||||
let entityDescription = fetchRequest.entity!
|
||||
if let attributeDescription = attributeDescriptionForKeyPath(keyPath, inEntity: entityDescription) {
|
||||
if let attributeDescription = attributeDescription(for: keyPath, in: entityDescription) {
|
||||
|
||||
propertiesToFetch.append(attributeDescription)
|
||||
}
|
||||
@@ -789,7 +782,7 @@ internal extension Collection where Iterator.Element == SelectTerm {
|
||||
|
||||
case ._aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
let entityDescription = fetchRequest.entity!
|
||||
if let attributeDescription = attributeDescriptionForKeyPath(keyPath, inEntity: entityDescription) {
|
||||
if let attributeDescription = attributeDescription(for: keyPath, in: entityDescription) {
|
||||
|
||||
let expressionDescription = NSExpressionDescription()
|
||||
expressionDescription.name = alias
|
||||
|
||||
@@ -145,7 +145,7 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
|
||||
public func applyToFetchRequest<ResultType: NSFetchRequestResult>(_ fetchRequest: NSFetchRequest<ResultType>) {
|
||||
|
||||
if let predicate = fetchRequest.predicate where predicate != self.predicate {
|
||||
if let predicate = fetchRequest.predicate, predicate != self.predicate {
|
||||
|
||||
CoreStore.log(
|
||||
.warning,
|
||||
|
||||
Reference in New Issue
Block a user