Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preconditions on mutation #9

Merged
merged 1 commit into from Nov 6, 2019

Conversation

@mpenet
Copy link
Member

mpenet commented Nov 6, 2019

These are queries that will run within the same transaction as mutations. They perform select(s) that must conform to a validator or if no validator is supplied return a non empty result. We can have multiple pre conditions for a single mutation, they are tried in order and will cause a rollback/abort of the transaction in case they fail.

It looks like this in the schema:

:mutations
{:user/update {:pre [{:name ::u0a0?
                      :valid? (fn [result] ....) ;; optional, defaults to (seq result)
                      :query (fn [user]
                               (-> (h/select :*)
                                   (h/from :user)
                                   (h/where [:= :name "u0a0"]
                                            [:= :id (:user/id user)])))}]
               :handler
               (fn [{:keys [:user/id] :as params}]
                 (-> (h/update :user)
                     (h/sset (dissoc params :user/id))
                     (h/where [:= :id id])))}}}}

[ch6406]

These are queries that will run within the same transaction as
mutations. They perform select(s) that must conform to a validator or
if no validator is supplied return a non empty result.
@pyr
pyr approved these changes Nov 6, 2019
@mpenet mpenet merged commit 12f3238 into master Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.