PostReactionTransaction
struct PostReactionTransaction<Post> where Post : Model, Post.IDValue == Int
Serializes reaction writes to a single post and advances the post’s reactionRevision when they change anything.
The transaction starts by locking the post’s row, which is held until commit, so concurrent writers queue behind it, including when the post has no reactions yet and across server processes. Anything the body reads or writes afterwards sees state no other reaction writer can change.
-
Declaration
Swift
let postID: Int -
Declaration
Swift
init(_ post: Post) throws -
run(on:Asynchronous_: ) Runs
bodyon the transaction’s database.bodyreturns whether it changed the post’s reactions; only then is the revision advanced, in the same commit. Returns that same value.Declaration
Swift
@discardableResult func run(on db: Database, _ body: @escaping @Sendable (Database) async throws -> Bool) async throws -> Bool
View on GitHub