InMemoryTransaction
public final class InMemoryTransaction : Transaction
This class represents a transaction for an in-memory database.
-
Undocumented
Declaration
Swift
public let eventLoop: EventLoop -
The version of the database that the reads for this transaction start from.
Declaration
Swift
public var readVersion: Int64 -
The database we are reading from.
Declaration
Swift
public let database: InMemoryDatabaseConnection -
Whether we’ve committed this transaction.
Declaration
Swift
public var committed: Bool -
Whether we’ve cancelled this transaction.
Declaration
Swift
public var cancelled: Bool -
The version at which we committed this transaction.
Declaration
Swift
public var committedVersion: Int64? -
This method reads a value from the data store.
Declaration
Swift
public func read(_ key: DatabaseValue, snapshot: Bool) -> EventLoopFuture<DatabaseValue?>Parameters
snapshotWhether we should perform a snapshot read.
Return Value
The value that we are reading, if any exists.
-
This method finds a key using a key selector.
Declaration
Swift
public func findKey(selector: KeySelector, snapshot: Bool) -> EventLoopFuture<DatabaseValue?>Parameters
selectorThe selector telling us where to find the key.
snapshotWhether we should perform a snapshot read when finding the key.
Return Value
The first key matching this selector.
-
This method reads a range of values for a range of keys matching two key selectors.
The keys included in the result range will be from the first key matching the start key selector to the first key matching the end key selector. The start key will be included in the results, but the end key will not.
The results will be ordered in lexographic order by their keys.
This will automatically add a read conflict for the range, so that if any key has changed in this range since the start of this transaction this transaction will not be accepted.
Declaration
Swift
public func readSelectors(from start: KeySelector, to end: KeySelector, limit: Int?, mode: StreamingMode, snapshot: Bool, reverse: Bool) -> EventLoopFuture<ResultSet>Parameters
fromThe key selector for the beginning of the range.
endThe key selector for the end of the range.
limitThe maximum number of results to return.
modeThe streaming mode to use.
snapshotWhether we should perform a snapshot read.
reverseWhether we should return the rows in reverse order.
Return Value
A list of rows with the keys and their corresponding values.
-
This method adds a change to the transaction.
Declaration
Swift
public func store(key: DatabaseValue, value: DatabaseValue)Parameters
keyThe key we are changing.
valueThe new value for the key.
-
This method clears a value in the database.
Declaration
Swift
public func clear(key: DatabaseValue)Parameters
keyThe key to clear.
-
This method clears a range of keys in the database.
Declaration
Swift
public func clear(range: Range<DatabaseValue>)Parameters
startThe beginning of the range to clear.
endThe end of the range to clear. This will not be included in the range.
-
This method adds a read conflict for a key range.
Declaration
Swift
public func addReadConflict(on range: Range<DatabaseValue>)Parameters
rangeThe range of keys we are adding the conflict on.
-
This method adds a range of keys that we want to reserve for writing.
If the system commits this transaction, and another transaction has a read conflict on one of these keys, that second transaction will then fail to commit.
Declaration
Swift
public func addWriteConflict(on range: Range<DatabaseValue>)Parameters
rangeThe range of keys to add the conflict on.
-
This method gets the version of the database that this transaction is reading from.
Declaration
Swift
public func getReadVersion() -> EventLoopFuture<Int64> -
This method gets the version of the database that this transaction should read from.
Declaration
Swift
public func setReadVersion(_ version: Int64)Parameters
versionThe new version.
-
This method gets the version of the database that this transaction committed its changes at.
If the transaction has not committed, this will return -1.
Declaration
Swift
public func getCommittedVersion() -> EventLoopFuture<Int64> -
This method resets the transaction to its initial state.
Declaration
Swift
public func reset() -
This method cancels the transaction, preventing it from being committed and freeing up some associated resources.
Declaration
Swift
public func cancel() -
This method attempts to retry a transaction after an error.
If the error is retryable, this will reset the transaction and fire the returned future when the transaction is ready to use again. If the error is not retryable, the returned future will rethrow the error.
Declaration
Swift
public func attemptRetry(error: Error) -> EventLoopFuture<Void>Parameters
errorThe error that the system encountered.
Return Value
A future indicating when the transaction is ready again.
-
This method performs an atomic operation against a key and value.
Declaration
Swift
public func performAtomicOperation(operation: MutationType, key: DatabaseValue, value: DatabaseValue)Parameters
operationThe operation to perform.
keyThe key to read for the operation.
valueThe new value to provide to the operation.
-
This method gets a version stamp, which is a key segment containing the committed version of the transaction.
This can be called before the transaction is committed, and it will only return a value once the transaction is committed.
Declaration
Swift
public func getVersionStamp() -> EventLoopFuture<DatabaseValue> -
This method sets an option on the transaction.
Declaration
Swift
public func setOption(_ option: TransactionOption, value: DatabaseValue?)Parameters
optionThe option to set.
valueThe value to set for the option.
View on GitHub
InMemoryTransaction Class Reference