Transaction
public final class Transaction
Thread-safe Transaction object
-
Check whether is already in transaction.
Declaration
Swift
public private(set) var isInTransaction: Bool = false -
The number of changed rows in the most recent call.
It should be called after executing successfullyDeclaration
Swift
public var changes: Int
-
The path of the related database.
Declaration
Swift
public var path: String -
The tag of the related database.
Declaration
Swift
public var tag: Tag? -
Prepare a specific sql.
Note that you can use this interface to prepare a SQL that is not contained in the WCDB interface layerThrows
ErrorDeclaration
Swift
public func prepare(_ statement: Statement) throws -> CoreStatementParameters
statementWINQ statement
Return Value
CoreStatement
-
Exec a specific sql.
Note that you can use this interface to execute a SQL that is not contained in the WCDB interface layer.Throws
ErrorDeclaration
Swift
public func exec(_ statement: Statement) throwsParameters
statementWINQ statement
-
Check whether table exists
Throws
ErrorDeclaration
Swift
public func isTableExists(_ table: String) throws -> BoolParameters
tableThe name of the table to be checked.
Return Value
True if table exists. False if table does not exist.
-
This interface is equivalent
begin(.immediate)Throws
ErrorDeclaration
Swift
public func begin() throws -
Separate interface of
run(transaction:)
You should callbegin,commit,rollbackand all other operations in same thread.
To do a cross-thread transaction, usegetTransaction.Throws
ErrorDeclaration
Swift
public func begin(_ mode: StatementTransaction.Mode) throws -
Separate interface of
run(transaction:)
You should callbegin,commit,rollbackand all other operations in same thread. To do a cross-thread transaction, usegetTransaction.Throws
ErrorDeclaration
Swift
public func commit() throws -
Separate interface of run(transaction:) You should call
begin,commit,rollbackand all other operations in same thread.
To do a cross-thread transaction, usegetTransaction.Throws
ErrorDeclaration
Swift
public func rollback() throws -
Run a transaction in closure
try transaction.run(transaction: { () throws -> Void in try transaction.insert(objects: objects, intoTable: table) })Throws
ErrorDeclaration
Swift
public func run(transaction: TransactionClosure) throwsParameters
transactionOperation inside transaction
-
Run a controlable transaction in closure
try transaction.run(controlableTransaction: { () throws -> Bool in try transaction.insert(objects: objects, intoTable: table) return true // return true to commit transaction and return false to rollback transaction. })Throws
ErrorDeclaration
Swift
public func run(controlableTransaction: ControlableTransactionClosure) throwsParameters
controlableTransactionOperation inside transaction
-
Run a embedded transaction in closure
The embedded transaction means that it will run a transaction if it’s not in other transaction, otherwise it will be executed within the existing transaction.try transaction.run(embeddedTransaction: { () throws -> Void in try transaction.insert(objects: objects, intoTable: table) })Throws
ErrorDeclaration
Swift
public func run(embeddedTransaction: TransactionClosure) throwsParameters
embeddedTransactionOperation inside transaction
View on GitHub
Install in Dash
Transaction Class Reference