Index: src/MTXSQLite3Storage.m ================================================================== --- src/MTXSQLite3Storage.m +++ src/MTXSQLite3Storage.m @@ -79,10 +79,15 @@ [_conn executeStatement: @"CREATE TABLE IF NOT EXISTS next_batch (\n" @" device_id TEXT PRIMARY KEY,\n" @" next_batch TEXT\n" @")"]; } + +- (void)transactionWithBlock: (mtx_storage_transaction_block_t)block +{ + [_conn transactionWithBlock: block]; +} - (void)setNextBatch: (OFString *)nextBatch forDeviceID: (OFString *)deviceID { void *pool = objc_autoreleasePoolPush(); Index: src/MTXStorage.h ================================================================== --- src/MTXStorage.h +++ src/MTXStorage.h @@ -22,14 +22,27 @@ #import OF_ASSUME_NONNULL_BEGIN +/** + * @brief A block which will be treated as a single transaction for the storage. + * + * @return Whether the transaction should be committed (`true`) or rolled back + * (`false`). + */ +typedef bool (^mtx_storage_transaction_block_t)(void); + /** * @brief A protocol for a storage to be used by @ref MTXClient. */ @protocol MTXStorage +/** + * @brief Performs all operations inside the block as a transaction. + */ +- (void)transactionWithBlock: (mtx_storage_transaction_block_t)block; + /** * @brief Stores the next batch for the specified device. * * @param nextBatch The next batch for the device * @param deviceID The device for which to store the next batch