Files
ent/examples/version
Ariel Mashraki 47972774c5 go: bump go/packages version ci to 1.18+1.19 (#2832)
* bumped pkg golang.org/x/tools version to address issue #2826

* .github: update go1.19 in go generate

Co-authored-by: Ankit Patial <ankitpatial@gmail.com>
2022-08-05 11:17:53 +03:00
..

Optimistic Lock

In this example, we implement an optimistic locking mechanism using the technique mentioned in Ent Blog.

The idea is to add to our schema a version field that holds the Unix time of when the latest update occurred. When an Update operation is executed, the hook updates the version field with the new value and adds a predicate to verify that the version wasn't updated by another process/transaction during the mutation.

An error is returned if the versions are mismatched, and the user should reload the entity and retry the mutation.

Generate Assets

go generate ./...

Run Example

go test