Classes

The following classes are available globally.

  • 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

    Declaration

    Swift

    public class AnyCursor<Element> : Cursor
  • An enumeration of the elements of a cursor.

    To create an instance of EnumeratedCursor, call the enumerated() method on a cursor:

    let cursor = try String.fetchCursor(db, "SELECT 'foo' UNION ALL SELECT 'bar'")
    let c = cursor.enumerated()
    while let (n, x) = c.next() {
        print("\(n): \(x)")
    }
    // Prints: "0: foo"
    // Prints: "1: bar"
    

    Declaration

    Swift

    public final class EnumeratedCursor<Base: Cursor> : Cursor
  • A cursor whose elements consist of the elements of some base cursor that also satisfy a given predicate.

    Declaration

    Swift

    public final class FilterCursor<Base: Cursor> : Cursor
  • A cursor consisting of all the elements contained in each segment contained in some Base cursor.

    See Cursor.joined(), Cursor.flatMap(:), Sequence.flatMap(:)

    Declaration

    Swift

    public final class FlattenCursor<Base: Cursor> : Cursor where Base.Element: Cursor
  • A Cursor whose elements consist of those in a Base Cursor passed through a transform function returning Element.

    See Cursor.map(_:)

    Declaration

    Swift

    public final class MapCursor<Base: Cursor, Element> : Cursor
  • A Cursor whose elements are those of a sequence iterator.

    See more

    Declaration

    Swift

    public final class IteratorCursor<Base: IteratorProtocol> : Cursor
  • A Database connection.

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

    let dbQueue = DatabaseQueue(...)
    
    // The Database is the `db` in the closure:
    try dbQueue.inDatabase { db in
        try db.execute(...)
    }
    
    See more

    Declaration

    Swift

    public final class Database
  • A cursor of database values extracted from a single column. For example:

    try dbQueue.inDatabase { db in
        let urls: DatabaseValueCursor<URL> = try URL.fetchCursor(db, "SELECT url FROM links")
        while let url = urls.next() { // URL
            print(url)
        }
    }
    

    Declaration

    Swift

    public final class DatabaseValueCursor<Value: DatabaseValueConvertible> : Cursor
  • A cursor of optional database values extracted from a single column. For example:

    try dbQueue.inDatabase { db in
        let urls: NullableDatabaseValueCursor<URL> = try Optional<URL>.fetchCursor(db, "SELECT url FROM links")
        while let url = urls.next() { // URL?
            print(url)
        }
    }
    

    Declaration

    Swift

    public final class NullableDatabaseValueCursor<Value: DatabaseValueConvertible> : Cursor
  • 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: "documents", using: FTS3()) { t in // t is FTS3TableDefinition
        t.column("content")
    }
    
    See more

    Declaration

    Swift

    public final class FTS3TableDefinition
  • 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: "documents", using: FTS4()) { t in // t is FTS4TableDefinition
        t.column("content")
    }
    

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

    See more

    Declaration

    Swift

    public final class FTS4TableDefinition
  • 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: "documents", using: FTS4()) { t in
        t.column("content")      // FTS4ColumnDefinition
    }
    

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

    See more

    Declaration

    Swift

    public final class FTS4ColumnDefinition
  • 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: "documents", 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: "documents", using: FTS5()) { t in
        t.column("content")      // FTS5ColumnDefinition
    }
    

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

    See more
  • RecordBox is a subclass of Record that aims at giving any record type the changes tracking provided by the Record class.

    // A Regular record struct
    struct Player: RowConvertible, MutablePersistable, Codable {
        static let databaseTableName = "players"
        var id: Int64?
        var name: String
        var score: Int
        mutating func didInsert(with rowID: Int64, for column: String?) {
            id = rowID
        }
    }
    
    try dbQueue.inDatabase { db in
        // Fetch a player record
        let playerRecord = try RecordBox<Player>.fetchOne(db, key: 1)!
    
        // Profit from changes tracking
        playerRecord.value.score = 300
        playerRecord.hasPersistentChangedValues         // true
        playerRecord.persistentChangedValues["score"]   // 100 (the old value)
    }
    
    See more

    Declaration

    Swift

    public final class RecordBox<T: RowConvertible & MutablePersistable>: Record
  • Row

    A database row.

    See more

    Declaration

    Swift

    public final class Row : Equatable, Hashable, RandomAccessCollection, ExpressibleByDictionaryLiteral, CustomStringConvertible
  • A cursor of database rows. For example:

    try dbQueue.inDatabase { db in
        let rows: RowCursor = try Row.fetchCursor(db, "SELECT * FROM players")
    }
    
    See more

    Declaration

    Swift

    public final class RowCursor : Cursor
  • A cursor of records. For example:

    struct Player : RowConvertible { ... }
    try dbQueue.inDatabase { db in
        let players: RecordCursor<Player> = try Player.fetchCursor(db, "SELECT * FROM players")
    }
    

    Declaration

    Swift

    public final class RecordCursor<Record: RowConvertible> : Cursor
  • A statement represents an SQL query.

    It is the base class of UpdateStatement that executes update statements, and SelectStatement that fetches rows.

    See more

    Declaration

    Swift

    public class Statement
  • A subclass of Statement that fetches database rows.

    You create SelectStatement with the Database.makeSelectStatement() method:

    try dbQueue.inDatabase { db in
        let statement = try db.makeSelectStatement("SELECT COUNT(*) FROM players WHERE score > ?")
        let moreThanTwentyCount = try Int.fetchOne(statement, arguments: [20])!
        let moreThanThirtyCount = try Int.fetchOne(statement, arguments: [30])!
    }
    
    See more

    Declaration

    Swift

    public final class SelectStatement : Statement
  • A cursor that iterates a database statement without producing any value. For example:

    try dbQueue.inDatabase { db in
        let statement = db.makeSelectStatement("SELECT * FROM players")
        let cursor: StatementCursor = statement.cursor()
    }
    
    See more

    Declaration

    Swift

    public final class StatementCursor: Cursor
  • A subclass of Statement that executes SQL queries.

    You create UpdateStatement with the Database.makeUpdateStatement() method:

    try dbQueue.inTransaction { db in
        let statement = try db.makeUpdateStatement("INSERT INTO players (name) VALUES (?)")
        try statement.execute(arguments: ["Arthur"])
        try statement.execute(arguments: ["Barbara"])
        return .commit
    }
    
    See more

    Declaration

    Swift

    public final class UpdateStatement : Statement
  • A cursor of database values extracted from a single column. For example:

    try dbQueue.inDatabase { db in
        let names: ColumnCursor<String> = try String.fetchCursor(db, "SELECT name FROM players")
        while let name = names.next() { // String
            print(name)
        }
    }
    

    Declaration

    Swift

    public final class ColumnCursor<Value: DatabaseValueConvertible & StatementColumnConvertible> : Cursor
  • A cursor of optional database values extracted from a single column. For example:

    try dbQueue.inDatabase { db in
        let emails: NullableColumnCursor<String> = try Optional<String>.fetchCursor(db, "SELECT email FROM players")
        while let email = emails.next() { // String?
            print(email ?? "<NULL>")
        }
    }
    

    Declaration

    Swift

    public final class NullableColumnCursor<Value: DatabaseValueConvertible & StatementColumnConvertible> : Cursor