Classes
The following classes are available globally.
-
A Database connection.
You don’t create a database directly. Instead, you use a DatabaseQueue, or a DatabasePool:
See morelet dbQueue = DatabaseQueue(...) // The Database is the `db` in the closure: try dbQueue.write { db in try Player(...).insert(db) }
Declaration
Swift
public final class Database : CustomStringConvertible, CustomDebugStringConvertible
-
A Collation is a string comparison function used by SQLite.
See moreDeclaration
Swift
public final class DatabaseCollation
extension DatabaseCollation: Hashable
-
An SQL function or aggregate.
See moreDeclaration
Swift
public final class DatabaseFunction : Hashable
-
A DatabasePool grants concurrent accesses to an SQLite database.
See moreDeclaration
Swift
public final class DatabasePool : DatabaseWriter
extension DatabasePool: @unchecked Sendable
extension DatabasePool: DatabaseReader
-
A DatabaseQueue serializes access to an SQLite database.
See moreDeclaration
Swift
public final class DatabaseQueue : DatabaseWriter
-
A type-erased DatabaseReader
Instances of AnyDatabaseReader forward their methods to an arbitrary underlying database reader.
See moreDeclaration
Swift
public final class AnyDatabaseReader : DatabaseReader
-
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 moreDeclaration
Swift
public final class DatabaseSnapshot : DatabaseReader
-
A cursor of database values extracted from a single column. For example:
See moretry 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) } }
Declaration
Swift
public final class DatabaseValueCursor<Value> : DatabaseCursor where Value : DatabaseValueConvertible
-
A cursor of optional database values extracted from a single column. For example:
See moretry dbQueue.read { db in let urls: NullableDatabaseValueCursor<URL> = try Optional<URL>.fetchCursor(db, sql: "SELECT url FROM link") while let url = urls.next() { // URL? print(url) } }
Declaration
Swift
public final class NullableDatabaseValueCursor<Value> : DatabaseCursor where Value : DatabaseValueConvertible
-
A future database value, returned by the DatabaseWriter.concurrentRead(_:) method.
See morelet 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()
Declaration
Swift
public class DatabaseFuture<Value>
-
A type-erased DatabaseWriter
Instances of AnyDatabaseWriter forward their methods to an arbitrary underlying database writer.
See moreDeclaration
Swift
public final class AnyDatabaseWriter : DatabaseWriter
-
A database row.
See moreDeclaration
Swift
public final class Row: Equatable, Hashable, RandomAccessCollection, ExpressibleByDictionaryLiteral, CustomStringConvertible, CustomDebugStringConvertible
-
A cursor of database rows. For example:
See moretry dbQueue.read { db in let rows: RowCursor = try Row.fetchCursor(db, sql: "SELECT * FROM player") }
Declaration
Swift
public final class RowCursor : DatabaseCursor
-
A statement represents an SQL query.
See moreDeclaration
Swift
public final class Statement
extension Statement: _RowLayout
extension Statement: CustomStringConvertible
-
A cursor of database values extracted from a single column. For example:
See moretry 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) } }
Declaration
Swift
public final class FastDatabaseValueCursor<Value>: DatabaseCursor where Value: DatabaseValueConvertible & StatementColumnConvertible
-
A cursor of optional database values extracted from a single column. For example:
See moretry dbQueue.read { db in let emails: FastNullableDatabaseValueCursor<String> = try Optional<String>.fetchCursor(db, sql: "SELECT email FROM player") while let email = emails.next() { // String? print(email ?? "<NULL>") } }
Declaration
Swift
public final class FastNullableDatabaseValueCursor<Value>: DatabaseCursor where Value: DatabaseValueConvertible & StatementColumnConvertible
-
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:
See moretry db.create(virtualTable: "document", using: FTS3()) { t in // t is FTS3TableDefinition t.column("content") }
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: "document", using: FTS4()) { t in // t is FTS4TableDefinition t.column("content") }
See https://www.sqlite.org/fts3.html
See moreDeclaration
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: "document", using: FTS4()) { t in t.column("content") // FTS4ColumnDefinition }
See https://www.sqlite.org/fts3.html
See moreDeclaration
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: "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
-
Declaration
Swift
public class TableAlias : Hashable
-
The TableDefinition class lets you define table columns and constraints.
You don’t create instances of this class. Instead, you use the Database
create(table:)
method:try db.create(table: "player") { t in // t is TableDefinition t.column(...) }
See https://www.sqlite.org/lang_createtable.html
See moreDeclaration
Swift
public final class TableDefinition
-
The TableAlteration class lets you alter database tables.
You don’t create instances of this class. Instead, you use the Database
alter(table:)
method:try db.alter(table: "player") { t in // t is TableAlteration t.add(column: ...) }
See https://www.sqlite.org/lang_altertable.html
See moreDeclaration
Swift
public final class TableAlteration
-
The ColumnDefinition class lets you refine a table column.
You get instances of this class when you create or alter a database table:
try db.create(table: "player") { t in t.column(...) // ColumnDefinition } try db.alter(table: "player") { t in t.add(column: ...) // ColumnDefinition }
See https://www.sqlite.org/lang_createtable.html and https://www.sqlite.org/lang_altertable.html
See moreDeclaration
Swift
public final class ColumnDefinition
-
A cursor of records. For example:
See morestruct Player : FetchableRecord { ... } try dbQueue.read { db in let players: RecordCursor<Player> = try Player.fetchCursor(db, sql: "SELECT * FROM player") }
Declaration
Swift
public final class RecordCursor<Record> : DatabaseCursor where Record : FetchableRecord
-
Record is a class that wraps a table row, or the result of any query. It is designed to be subclassed.
See moreDeclaration
Swift
open class Record : FetchableRecord, TableRecord, PersistableRecord
-
A type-erasing cancellable object that executes a provided closure when canceled.
An AnyDatabaseCancellable instance automatically calls cancel() when deinitialized.
See moreDeclaration
Swift
public class AnyDatabaseCancellable : DatabaseCancellable
-
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:
See more// 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(...)
Declaration
Swift
public final class SharedValueObservation<Element>
-
ValueObservationScheduler determines how
See moreValueObservation
notifies its fresh values.Declaration
Swift
public class ValueObservationScheduler