Classes

The following classes are available globally.

Specialized Cursors

  • A type-erased cursor of Element.

    This cursor forwards its next() method to an arbitrary underlying cursor having the same Element type, hiding the specifics of the underlying cursor.

    See more
  • A Database connection.

    You don’t create a database directly. Instead, you use a DatabaseQueue, or a DatabasePool:

    let dbQueue = try DatabaseQueue(...)
    
    // The Database is the `db` in the closure:
    try dbQueue.write { db in
        try Player(...).insert(db)
    }
    
    See more
  • A cursor over all statements in a SQL string.

    See more
  • A Collation is a string comparison function used by SQLite.

    See more

    Declaration

    Swift

  • An SQL function or aggregate.

    See more
  • A DatabasePool grants concurrent accesses to an SQLite database.

    See more

    Declaration

    Swift

  • A DatabaseQueue serializes access to an SQLite database.

    See more
  • A type-erased DatabaseReader

    Instances of AnyDatabaseReader forward their methods to an arbitrary underlying database reader.

    See more
  • A DatabaseSnapshot sees an unchanging database content, as it existed at the moment it was created.

    See DatabasePool.makeSnapshot()

    For more information, read about “snapshot isolation” at https://sqlite.org/isolation.html

    See more

Cursors

  • A cursor of database values extracted from a single column. For example:

    try dbQueue.read { db in
        let urls: DatabaseValueCursor<URL> = try URL.fetchCursor(db, sql: "SELECT url FROM link")
        while let url = urls.next() { // URL
            print(url)
        }
    }
    
    See more
  • A future database value, returned by the DatabaseWriter.concurrentRead(_:) method.

    let futureCount: Future<Int> = try writer.writeWithoutTransaction { db in
        try Player(...).insert()
    
        // Count players concurrently
        return writer.concurrentRead { db in
            return try Player.fetchCount()
        }
    }
    
    let count: Int = try futureCount.wait()
    
    See more
  • A type-erased DatabaseWriter

    Instances of AnyDatabaseWriter forward their methods to an arbitrary underlying database writer.

    See more
  • Row

    A database row.

    See more

RowCursor

  • A cursor of database rows. For example:

    try dbQueue.read { db in
        let rows: RowCursor = try Row.fetchCursor(db, sql: "SELECT * FROM player")
    }
    
    See more
  • A statement represents an SQL query.

    See more

    Declaration

    Swift

Cursors

  • A cursor of database values extracted from a single column. For example:

    try dbQueue.read { db in
        let names: ColumnCursor<String> = try String.fetchCursor(db, sql: "SELECT name FROM player")
        while let name = names.next() { // String
            print(name)
        }
    }
    
    See more
  • The FTS3TableDefinition class lets you define columns of a FTS3 virtual table.

    You don’t create instances of this class. Instead, you use the Database create(virtualTable:using:) method:

    try db.create(virtualTable: "document", using: FTS3()) { t in // t is FTS3TableDefinition
        t.column("content")
    }
    
    See more
  • The FTS4TableDefinition class lets you define columns of a FTS4 virtual table.

    You don’t create instances of this class. Instead, you use the Database create(virtualTable:using:) method:

    try db.create(virtualTable: "document", using: FTS4()) { t in // t is FTS4TableDefinition
        t.column("content")
    }
    

    See https://www.sqlite.org/fts3.html

    See more
  • The FTS4ColumnDefinition class lets you refine a column of an FTS4 virtual table.

    You get instances of this class when you create an FTS4 table:

    try db.create(virtualTable: "document", using: FTS4()) { t in
        t.column("content")      // FTS4ColumnDefinition
    }
    

    See https://www.sqlite.org/fts3.html

    See more
  • The FTS5TableDefinition class lets you define columns of a FTS5 virtual table.

    You don’t create instances of this class. Instead, you use the Database create(virtualTable:using:) method:

    try db.create(virtualTable: "document", using: FTS5()) { t in // t is FTS5TableDefinition
        t.column("content")
    }
    

    See https://www.sqlite.org/fts5.html

    See more
  • The FTS5ColumnDefinition class lets you refine a column of an FTS5 virtual table.

    You get instances of this class when you create an FTS5 table:

    try db.create(virtualTable: "document", using: FTS5()) { t in
        t.column("content")      // FTS5ColumnDefinition
    }
    

    See https://www.sqlite.org/fts5.html

    See more

TableAlias

RecordCursor

  • A cursor of records. For example:

    struct Player : FetchableRecord { ... }
    try dbQueue.read { db in
        let players: RecordCursor<Player> = try Player.fetchCursor(db, sql: "SELECT * FROM player")
    }
    
    See more

Record

  • Record is a class that wraps a table row, or the result of any query. It is designed to be subclassed.

    See more
  • A type-erasing cancellable object that executes a provided closure when canceled.

    An AnyDatabaseCancellable instance automatically calls cancel() when deinitialized.

    See more
  • Experimental

    A shared value observation that shares a single underlying database observation for all subscriptions, and thus spares database resources.

    For example:

    let sharedObservation = ValueObservation
        .tracking { db in try Player.fetchAll(db) }
        .shared(in: dbQueue)
    
    let cancellable = try sharedObservation.start(
        onError: { error in ... },
        onChange: { (players: [Player]) in
            print("Players have changed.")
        })
    

    The sharing only applies if you start observing the database from the same SharedValueObservation instance:

    // NOT shared
    let cancellable1 = ValueObservation.tracking { db in ... }.shared(in: dbQueue).start(...)
    let cancellable2 = ValueObservation.tracking { db in ... }.shared(in: dbQueue).start(...)
    
    // Shared
    let sharedObservation = ValueObservation.tracking { db in ... }.shared(in: dbQueue)
    let cancellable1 = sharedObservation.start(...)
    let cancellable2 = sharedObservation.start(...)
    
    See more
  • ValueObservationScheduler determines how ValueObservation notifies its fresh values.

    See more