PropertyQuery

public class PropertyQuery<E, T> where E : Entity, T : EntityPropertyTypeConvertible

Query for values of a specific property instead of object instances.

Create using Query.property(_:). Use Query if you want to obtain entities.

PropertyQuery will respect the conditions of its base Query. So if you want to find the average age of all Persons above 30, this is how you can write it:

 let query = personBox.query { Person.age > 29 }
 let ageQuery = query.property(Person.age)
 let averageAge = ageQuery.average

Note

Property values do currently not consider any sorting order defined in the main Query object.
  • The entity type this query is targeting.

    Declaration

    Swift

    public typealias EntityType = E
  • The type of the entity’s property this query is targeting.

    Declaration

    Swift

    public typealias ValueType = T
  • The count of objects matching this query.

    Declaration

    Swift

    public var count: Int { get }
  • Change this PropertyQuery to verify there is only a single value among the query result.

    For find methods returning single values, e.g. findInt(), this will additionally verify that the resulting value is unique. If there is any other resulting value resulting from this query, a runtime exception will be thrown.

    Note

    Cannot be unset.

    Declaration

    Swift

    @discardableResult
    public func unique() -> PropertyQuery<EntityType, ValueType>

    Return Value

    self for chaining

  • Indicates if results are verified to be unique.

    Declaration

    Swift

    public var isUnique: Bool { get }
  • Enable that only distinct values should be returned (e.g. 1,2,3 instead of 1,1,2,3,3,3).

    Note

    Cannot be unset.

    Declaration

    Swift

    @discardableResult
    public func distinct() -> PropertyQuery<EntityType, ValueType>

    Return Value

    self for chaining

  • True if only distinct values should be returned (e.g. 1,2,3 instead of 1,1,2,3,3,3).

    Declaration

    Swift

    public var isDistinct: Bool { get }
  • sum

    Sums up all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var sum: Int { get }
  • max

    Finds the maximum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var max: Int { get }
  • min

    Finds the minimum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var min: Int { get }
  • Calculates the average of all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var average: Double { get }
  • Find the values for the given property for objects matching the query.

    Note

    Results are not guaranteed to be in any particular order.

    Declaration

    Swift

    public func findIntegers() -> [Int]

    Return Value

    Values for the given property.

  • Find a value for the given property.

    Declaration

    Swift

    public func findInteger() -> Int?

    Return Value

    A value of the objects matching the query, nil if no value was found.

  • sum

    Sums up all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var sum: Int64 { get }
  • max

    Finds the maximum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var max: Int64 { get }
  • min

    Finds the minimum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var min: Int64 { get }
  • Calculates the average of all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var average: Double { get }
  • Find the values for the given property for objects matching the query.

    Note

    Results are not guaranteed to be in any particular order.

    Declaration

    Swift

    public func findLongs() -> [Int64]

    Return Value

    Values for the given property.

  • Find the values for the given property for objects matching the query.

    Note

    Results are not guaranteed to be in any particular order.

    Declaration

    Swift

    public func findInt64s() -> [Int64]

    Return Value

    Values for the given property.

  • Find a value for the given property.

    Declaration

    Swift

    public func findLong() -> Int64?

    Return Value

    A value of the objects matching the query, nil if no value was found.

  • Find a value for the given property.

    Declaration

    Swift

    public func findInt64() -> Int64?

    Return Value

    A value of the objects matching the query, nil if no value was found.

  • sum

    Sums up all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var sum: Int { get }
  • max

    Finds the maximum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var max: Int { get }
  • min

    Finds the minimum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var min: Int { get }
  • Calculates the average of all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var average: Double { get }
  • sum

    Sums up all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var sum: Int { get }
  • max

    Finds the maximum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var max: Int { get }
  • min

    Finds the minimum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var min: Int { get }
  • Calculates the average of all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var average: Double { get }
  • sum

    Sums up all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var sum: Int { get }
  • max

    Finds the maximum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var max: Int { get }
  • min

    Finds the minimum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var min: Int { get }
  • Calculates the average of all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var average: Double { get }
  • sum

    Sums up all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var sum: Double { get }
  • max

    Finds the maximum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var max: Double { get }
  • min

    Finds the minimum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var min: Double { get }
  • Calculates the average of all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var average: Double { get }
  • sum

    Sums up all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var sum: Double { get }
  • max

    Finds the maximum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var max: Double { get }
  • min

    Finds the minimum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public var min: Double { get }
  • Calculates the average of all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public var average: Double { get }
  • Declaration

    Swift

    @discardableResult
    public func distinct(caseSensitiveCompare: Bool = true) -> PropertyQuery<EntityType, ValueType>

    Parameters

    caseSensitiveCompare

    Specifies if [foo, FOO, Foo] counts as 1.

    Return Value

    self for chaining

  • Find the values for the given property for objects matching the query.

    Note

    Results are not guaranteed to be in any particular order.

    Declaration

    Swift

    public func findStrings() -> [String]

    Return Value

    String values for the given property.

  • Find a value for the given property.

    Declaration

    Swift

    public func findString() -> String?

    Return Value

    A value of the objects matching the query, nil if no value was found.

  • Set a replacement string for nil results.

    Declaration

    Swift

    @discardableResult
    public func with(nullString: String) -> PropertyQuery<EntityType, ValueType>

    Return Value

    self for chaining