Configuration

public struct Configuration

Configuration for a DatabaseQueue or DatabasePool.

  • If true, foreign key constraints are checked.

    Default: true

    Declaration

    Swift

    public var foreignKeysEnabled: Bool = true
  • If true, database modifications are disallowed.

    Default: false

    Declaration

    Swift

    public var readonly: Bool = false
  • A function that is called on every statement executed by the database.

    Default: nil

    Declaration

    Swift

    public var trace: TraceFunction?
  • The passphrase for encrypted database.

    Default: nil

  • The default kind of transaction.

    Default: deferred

    Declaration

    Swift

    public var defaultTransactionKind: Database.TransactionKind = .deferred
  • If false, it is a programmer error to leave a transaction opened at the end of a database access block.

    For example:

    let dbQueue = DatabaseQueue()
    
    // fatal error: A transaction has been left opened at the end of a database access
    try dbQueue.inDatabase { db in
        try db.beginTransaction()
    }
    

    If true, one can leave opened transaction at the end of database access blocks:

    var config = Configuration()
    config.allowsUnsafeTransactions = true
    let dbQueue = DatabaseQueue(configuration: config)
    
    try dbQueue.inDatabase { db in
        try db.beginTransaction()
    }
    
    try dbQueue.inDatabase { db in
        try db.commit()
    }
    

    This configuration flag has no effect on DatabasePool readers: those never allow leaving a transaction opened at the end of a read access.

    Default: false

    Declaration

    Swift

    public var allowsUnsafeTransactions: Bool = false