Query

public class Query

A database query. A Query instance can be constructed by calling one of the select class methods.

  • Create a SELECT ALL (*) statement instance. You can then call the Select instance’s methods such as from() method to construct the complete Query instance.

    Declaration

    Swift

    public static func select() -> Select
  • Create a SELECT DISTINCT ALL (*) statement instance. You can then call the Select instance’s methods such as from() method to construct the complete Query instance.

    Declaration

    Swift

    public static func selectDistinct() -> Select
  • Runs the query. The returning an enumerator that returns result rows one at a time. You can run the query any number of times, and you can even have multiple enumerators active at once. The results come from a snapshot of the database taken at the moment -run: is called, so they will not reflect any changes made to the database afterwards.

    Declaration

    Swift

    public func run() throws -> QueryIterator
  • Returns a string describing the implementation of the compiled query. This is intended to be read by a developer for purposes of optimizing the query, especially to add database indexes. It’s not machine-readable and its format may change.

    As currently implemented, the result is two or more lines separated by newline characters:
    * The first line is the SQLite SELECT statement.
    * The subsequent lines are the output of SQLite's "EXPLAIN QUERY PLAN" command applied to that
      statement; for help interpreting this, see https://www.sqlite.org/eqp.html . The most
      important thing to know is that if you see "SCAN TABLE", it means that SQLite is doing a
      slow linear scan of the documents instead of using an index.
    @param outError If an error occurs, it will be stored here if this parameter is non-NULL.
    @return a string describing the implementation of the compiled query.
    

    Declaration

    Swift

    public func explain() throws -> String
  • Returns a live query based on the current query. @return a live query object.

    Declaration

    Swift

    public func toLive() -> LiveQuery