Database represents a raw SQLite connection. You don’t create instances directly; instead, access them through DatabaseQueue or DatabasePool access methods.
Overview
Properties
The database configuration
The rowID of the most recently inserted row
The number of rows modified by the most recent INSERT, UPDATE, or DELETE
The total number of rows modified since the connection was opened
Whether the database is currently inside a transaction
The date of the current transaction (constant during a transaction)
Executing SQL
execute(sql:arguments:)
Executes an SQL statement.The SQL statement to execute
Optional statement arguments
execute(literal:)
Executes an SQL literal with interpolated values.Creating Statements
makeStatement(sql:)
Creates a reusable prepared statement.cachedStatement(sql:)
Returns a cached prepared statement for better performance.Cached statements are automatically cleared when the database schema changes.
Transactions
beginTransaction(_:)
Begins a transaction.The transaction kind:
.deferred, .immediate, or .exclusivecommit()
Commits the current transaction.rollback()
Rolls back the current transaction.inTransaction(::)
Executes a closure in a transaction.inSavepoint(_:)
Executes a closure in a savepoint.Savepoints can be nested and allow partial rollbacks within a transaction.
Database Functions
add(function:)
Adds a custom SQL function.remove(function:)
Removes a custom SQL function.Collations
add(collation:)
Adds a custom collation for text comparison.Database Observation
add(transactionObserver:extent:)
Adds a transaction observer to monitor database changes.registerAccess(to:)
Registers that a specific database region is accessed during a ValueObservation.notifyChanges(in:)
Notifies observers that changes occurred in a database region.Database Information
lastErrorCode
The last SQLite error code.lastErrorMessage
The last SQLite error message.maximumStatementArgumentCount
The maximum number of arguments an SQLite statement can accept.Memory Management
releaseMemory()
Frees as much memory as possible.clearSchemaCache()
Clears the cached database schema information.Checkpoints
checkpoint(_:on:)
Performs a WAL checkpoint.The checkpoint mode:
.passive, .full, .restart, or .truncateThe database name
Tracing
trace(options:_:)
Traces SQL statements and other database events.Read-Only Mode
readOnly(_:)
Executes operations in read-only mode.Static Properties
Global error logging function
SQLite library version number
Notifications
Notification posted to suspend database operations
Notification posted to resume database operations
Related Types
Statement- Prepared SQL statementDatabaseFunction- Custom SQL functionDatabaseCollation- Custom text collationTransactionObserver- Database change observer