QueryBuilder

public final class QueryBuilder<E: EntityInspectable & __EntityRelatable>
where E == E.EntityBindingType.EntityType

Undocumented

  • The type of entity this query builder operates on.

    Declaration

    Swift

    public typealias EntityType = E
  • Undocumented

    Declaration

    Swift

    public typealias QueryProperty<T> = Property<EntityType, T, Void> where T : EntityPropertyTypeConvertible
  • Build a query from the information in this query builder, which can then be used to get actual query results from the database.

    Declaration

    Swift

    public func build() throws -> Query<EntityType>
  • Request that query results for an entity query be returned sorted by the given property. Can not be called after the query has been used the first time.

    Currently has no effect on the result of calling query.property(...).

    Declaration

    Swift

    public func ordered<T>(by property: Property<EntityType, T, Void>, flags: [OrderFlags] = [])
                    -> QueryBuilder<EntityType>

    Parameters

    property

    The property by which to sort.

    flags

    Additional flags to control sort behaviour, like what to do with NIL values, or to sort descending instead of ascending.

  • Overload of ordered() taking a single flag only.

    Declaration

    Swift

    public func ordered<T>(by property: Property<EntityType, T, Void>, flags: OrderFlags)
                    -> QueryBuilder<EntityType>
  • Adds an and-relation to another entity referenced by a ToOne property of this entity to this query.

    Note

    in relational databases you would use a “join” for this.

    Declaration

    Swift

    func link<V: IdBase, R>(_ property: Property<E, V, R>,
                            conditions: @escaping () -> QueryCondition<R>)
        -> QueryBuilder<E>
        where R == R.EntityBindingType.EntityType

    Parameters

    property

    The ToOne relation property you wish to traverse for your query.

    conditions

    The query you want to execute on the referenced property.

    Return Value

    This object, so you can chain calls like orderBox.query().link(property: Order.customer) { Customer.name == "Sally Sparrow" }.build()

  • Adds an and-relation to another entity referenced by a ToMany property of this entity to this query.

    Note: in relational databases you would use a “join” for this.

    Declaration

    Swift

    func link<V: EntityInspectable>(_ property: ToManyProperty<V>,
                                    conditions: @escaping () -> QueryCondition<V>)
        -> QueryBuilder<E>
        where V == V.EntityBindingType.EntityType

    Parameters

    property

    The ToMany relation property you wish to traverse for your query.

    conditions

    The query you want to execute on the referenced property.

    Return Value

    This object, so you can chain calls like customerBox.query().and(property: Customer.orders) { Order.name == "Paint Supplies" }.build()