PropertyQuery

public class PropertyQuery<E: EntityInspectable & __EntityRelatable, T: EntityPropertyTypeConvertible>
    where E == E.EntityBindingType.EntityType

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 = try personBox.query { Person.age > 29 }.build()
 let ageQuery = query.property(Person.age)
 let averageAge = try 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 func count() throws -> Int
  • 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() throws -> PropertyQuery<EntityType, ValueType>

    Return Value

    self for chaining

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

    Declaration

    Swift

    public func sum() throws -> Int64
  • Sums up all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public func sumInt() throws -> Int
  • Sums up all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public func sumUnsigned() throws -> UInt64
  • Finds the maximum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public func max() throws -> T
  • Finds the minimum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public func min() throws -> T
  • Calculates the average of all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public func average() throws -> Double
  • Calculates the average of all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public func averageInt() throws -> T
  • 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 find() throws -> [T]

    Return Value

    Values for the given property.

  • Find a unique value for the given property.

    Throws

    ObjectBoxError.uniqueViolation if more than 1 result was found.

    Declaration

    Swift

    public func findUnique() throws -> T?

    Return Value

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

  • Provide a value to return in place of nil from this property query.

    Declaration

    Swift

    @discardableResult
    public func with(nullValue: Int64) -> PropertyQuery<EntityType, ValueType>

    Return Value

    self for chaining

  • Provide a value to return in place of nil from this property query.

    Declaration

    Swift

    @discardableResult
    public func with(nullValue: Int64) -> PropertyQuery<EntityType, ValueType>

    Return Value

    self for chaining

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

    Declaration

    Swift

    public func sum() throws -> Double
  • Finds the maximum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public func max() throws -> Double
  • Finds the minimum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public func min() throws -> Double
  • Calculates the average of all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public func average() throws -> Double
  • 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 findDoubles() throws -> [Double]

    Return Value

    Values for the given property.

  • Find a unique value for the given property.

    Throws

    ObjectBoxError.uniqueViolation if more than 1 result was found.

    Declaration

    Swift

    public func findUniqueDouble() throws -> Double?

    Return Value

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

  • Provide a value to return in place of nil from this property query.

    Declaration

    Swift

    @discardableResult
    public func with(nullValue: Double) -> PropertyQuery<EntityType, ValueType>

    Return Value

    self for chaining

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

    Declaration

    Swift

    public func sum() throws -> Double
  • Finds the maximum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public func max() throws -> Float
  • Finds the minimum value for the given property over all Objects matching the query.

    Declaration

    Swift

    public func min() throws -> Float
  • Calculates the average of all values for the given property over all Objects matching the query.

    Declaration

    Swift

    public func average() throws -> Double
  • 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 findFloats() throws -> [Float]

    Return Value

    Values for the given property.

  • Find a unique value for the given property.

    Throws

    ObjectBoxError.uniqueViolation if more than 1 result was found.

    Declaration

    Swift

    public func findUniqueFloat() throws -> Float?

    Return Value

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

  • Provide a value to return in place of nil from this property query.

    Declaration

    Swift

    @discardableResult
    public func with(nullValue: Float) -> PropertyQuery<EntityType, ValueType>

    Return Value

    self for chaining

  • Declaration

    Swift

    @discardableResult
    public func distinct(caseSensitiveCompare: Bool = true) throws -> 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() throws -> [String]

    Return Value

    String values for the given property.

  • Find a value for the given property.

    Declaration

    Swift

    public func findString() throws -> String?

    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 findUniqueString() throws -> 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