Files
ent/examples/version
Nicholas Anderson 896f2b202d entc/gen: update NotSingularError godoc (#2274)
* fix: update only/onlyID comments

this patch updates the Only/OnlyID methods in the builder template from:

> // Returns a *NotSingularError when exactly one {{ $.Name }} entity is not found.
to
> // Returns a *NotSingularError when more than exactly one {{ $.Name }} ID is found.

in an effort to be more explicit in the explanation of the behavior of the methods.

* fix: update wording to be more concise from suggestion

Co-authored-by: Rotem Tamir <rotemtamir@gmail.com>

* fix: update Only wording to be more concicse

* fix: generate new files

Co-authored-by: Rotem Tamir <rotemtamir@gmail.com>
2022-01-23 19:07:10 +02: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