# QueryChainBuilder

    public struct QueryChainBuilder<O, R> : QueryChainableBuilderType where O : DynamicObject, R : SelectResultType

The fetch builder type used for a queries. A `QueryChainBuilder` is created from a `From` clause and then a `select(...)` chain.

    let averageAdultAge = dataStack.queryValue(
        From<MyPersonEntity>()
            .select(Int.self, .average(\.age))
            .where(\.age > 18)
    )

### QueryChainableBuilderType

- `ObjectType`

  #### Declaration

  Swift

      public typealias ObjectType = O

- `ResultType`

  #### Declaration

  Swift

      public typealias ResultType = R

- `from`

  #### Declaration

  Swift

      public var from: From<O>

- `select`

  #### Declaration

  Swift

      public var select: Select<O, R>

- `queryClauses`

  #### Declaration

  Swift

      public var queryClauses: [QueryClause]

### QueryChainBuilder

- `where(_:)`

  Adds a `Where` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func `where`(_ clause: Where<O>) -> QueryChainBuilder<O, R>

  #### Parameters

  `clause` | a `Where` clause to add to the query builder

  #### Return Value

  a new `QueryChainBuilder` containing the `Where` clause

- `where(combineByAnd:)`

  Creates a `FetchChainBuilder` that `AND`s the specified `Where` clauses. Use this overload if the compiler cannot infer the types when chaining multiple `&&` operators.

  #### Declaration

  Swift

      public func `where`(combineByAnd clauses: Where<O>...) -> QueryChainBuilder<O, R>

  #### Parameters

  `clauses` | the `Where` clauses to create a `FetchChainBuilder` with

  #### Return Value

  a `FetchChainBuilder` that `AND`s the specified `Where` clauses

- `where(combineByOr:)`

  Creates a `FetchChainBuilder` that `OR`s the specified `Where` clauses. Use this overload if the compiler cannot infer the types when chaining multiple `||` operators.

  #### Declaration

  Swift

      public func `where`(combineByOr clauses: Where<O>...) -> QueryChainBuilder<O, R>

  #### Parameters

  `clauses` | the `Where` clauses to create a `FetchChainBuilder` with

  #### Return Value

  a `FetchChainBuilder` that `OR`s the specified `Where` clauses

- `where(format:_:)`

  Adds a `Where` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func `where`(format: String, _ args: Any...) -> QueryChainBuilder<O, R>

  #### Parameters

  `format` | the format string for the predicate
  `args` | the arguments for `format`

  #### Return Value

  a new `QueryChainBuilder` containing the `Where` clause

- `where(format:argumentArray:)`

  Adds a `Where` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func `where`(format: String, argumentArray: [Any]?) -> QueryChainBuilder<O, R>

  #### Parameters

  `format` | the format string for the predicate
  `argumentArray` | the arguments for `format`

  #### Return Value

  a new `QueryChainBuilder` containing the `Where` clause

- `orderBy(_:)`

  Adds an `OrderBy` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func orderBy(_ clause: OrderBy<O>) -> QueryChainBuilder<O, R>

  #### Parameters

  `clause` | the `OrderBy` clause to add

  #### Return Value

  a new `QueryChainBuilder` containing the `OrderBy` clause

- `orderBy(_:_:)`

  Adds an `OrderBy` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func orderBy(_ sortKey: OrderBy<O>.SortKey, _ sortKeys: OrderBy<O>.SortKey...) -> QueryChainBuilder<O, R>

  #### Parameters

  `sortKey` | a single `SortKey`
  `sortKeys` | a series of other `SortKey`s

  #### Return Value

  a new `QueryChainBuilder` containing the `OrderBy` clause

- `orderBy(_:)`

  Adds an `OrderBy` clause to the `QueryChainBuild`

  #### Declaration

  Swift

      public func orderBy(_ sortKeys: [OrderBy<O>.SortKey]) -> QueryChainBuilder<O, R>

  #### Parameters

  `sortKeys` | a series of `SortKey`s

  #### Return Value

  a new `QueryChainBuilder` containing the `OrderBy` clause

- `tweak(_:)`

  Adds a `Tweak` clause to the `QueryChainBuilder` with a closure where the `NSFetchRequest` may be configured

  #### Declaration

  Swift

      public func tweak(_ fetchRequest: @escaping (NSFetchRequest<NSFetchRequestResult>) -> Void) -> QueryChainBuilder<O, R>

  #### Parameters

  `fetchRequest` | the block to customize the `NSFetchRequest`

  #### Return Value

  a new `QueryChainBuilder` containing the `Tweak` clause

- `groupBy(_:)`

  Adds a `GroupBy` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func groupBy(_ clause: GroupBy<O>) -> QueryChainBuilder<O, R>

  #### Parameters

  `clause` | a `GroupBy` clause to add to the query builder

  #### Return Value

  a new `QueryChainBuilder` containing the `GroupBy` clause

- `groupBy(_:_:)`

  Adds a `GroupBy` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func groupBy(_ keyPath: KeyPathString, _ keyPaths: KeyPathString...) -> QueryChainBuilder<O, R>

  #### Parameters

  `keyPath` | a key path to group the query results with
  `keyPaths` | other key paths to group the query results with

  #### Return Value

  a new `QueryChainBuilder` containing the `GroupBy` clause

- `groupBy(_:)`

  Adds a `GroupBy` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func groupBy(_ keyPaths: [KeyPathString]) -> QueryChainBuilder<O, R>

  #### Parameters

  `keyPaths` | a series of key paths to group the query results with

  #### Return Value

  a new `QueryChainBuilder` containing the `GroupBy` clause

- `appending(_:)`

  Appends a `QueryClause` to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func appending(_ clause: QueryClause) -> QueryChainBuilder<O, R>

  #### Parameters

  `clause` | the `QueryClause` to add to the `QueryChainBuilder`

  #### Return Value

  a new `QueryChainBuilder` containing the `QueryClause`

- `appending(contentsOf:)`

  Appends a series of `QueryClause`s to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func appending<S>(contentsOf clauses: S) -> QueryChainBuilder<O, R> where S : Sequence, S.Element == QueryClause

  #### Parameters

  `clauses` | the `QueryClause`s to add to the `QueryChainBuilder`

  #### Return Value

  a new `QueryChainBuilder` containing the `QueryClause`s

### Available where `O`: `NSManagedObject`

- `groupBy(_:)`

  Adds a `GroupBy` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func groupBy<T>(_ keyPath: KeyPath<O, T>) -> QueryChainBuilder<O, R>

  #### Parameters

  `keyPath` | a key path to group the query results with

  #### Return Value

  a new `QueryChainBuilder` containing the `GroupBy` clause

### Available where `O`: `CoreStoreObject`

- `where(_:)`

  Adds a `Where` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func `where`<T>(_ clause: (O) -> T) -> QueryChainBuilder<O, R> where T : AnyWhereClause

  #### Parameters

  `clause` | a `Where` clause to add to the query builder

  #### Return Value

  a new `QueryChainBuilder` containing the `Where` clause

- `groupBy(_:)`

  Adds a `GroupBy` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func groupBy<T>(_ keyPath: KeyPath<O, FieldContainer<O>.Stored<T>>) -> QueryChainBuilder<O, R> where T : FieldStorableType

  #### Parameters

  `keyPath` | a key path to group the query results with

  #### Return Value

  a new `QueryChainBuilder` containing the `GroupBy` clause

- `groupBy(_:)`

  Adds a `GroupBy` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func groupBy<T>(_ keyPath: KeyPath<O, FieldContainer<O>.Virtual<T>>) -> QueryChainBuilder<O, R>

  #### Parameters

  `keyPath` | a key path to group the query results with

  #### Return Value

  a new `QueryChainBuilder` containing the `GroupBy` clause

- `groupBy(_:)`

  Adds a `GroupBy` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func groupBy<T>(_ keyPath: KeyPath<O, FieldContainer<O>.Coded<T>>) -> QueryChainBuilder<O, R>

  #### Parameters

  `keyPath` | a key path to group the query results with

  #### Return Value

  a new `QueryChainBuilder` containing the `GroupBy` clause

- `groupBy(_:)`

  Adds a `GroupBy` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func groupBy<T>(_ keyPath: KeyPath<O, ValueContainer<O>.Required<T>>) -> QueryChainBuilder<O, R> where T : ImportableAttributeType

  #### Parameters

  `keyPath` | a key path to group the query results with

  #### Return Value

  a new `QueryChainBuilder` containing the `GroupBy` clause

- `groupBy(_:)`

  Adds a `GroupBy` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func groupBy<T>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<T>>) -> QueryChainBuilder<O, R> where T : ImportableAttributeType

  #### Parameters

  `keyPath` | a key path to group the query results with

  #### Return Value

  a new `QueryChainBuilder` containing the `GroupBy` clause

- `groupBy(_:)`

  Adds a `GroupBy` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func groupBy<T>(_ keyPath: KeyPath<O, TransformableContainer<O>.Required<T>>) -> QueryChainBuilder<O, R> where T : NSCoding, T : NSCopying

  #### Parameters

  `keyPath` | a key path to group the query results with

  #### Return Value

  a new `QueryChainBuilder` containing the `GroupBy` clause

- `groupBy(_:)`

  Adds a `GroupBy` clause to the `QueryChainBuilder`

  #### Declaration

  Swift

      public func groupBy<T>(_ keyPath: KeyPath<O, TransformableContainer<O>.Optional<T>>) -> QueryChainBuilder<O, R> where T : NSCoding, T : NSCopying

  #### Parameters

  `keyPath` | a key path to group the query results with

  #### Return Value

  a new `QueryChainBuilder` containing the `GroupBy` clause