Skip to content

Commit

Permalink
Add an example of select(update()) to the docs (#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh authored Jan 16, 2024
1 parent c991a82 commit 6fd983f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/update.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ You can conditionally update a property by using an :ref:`optional parameter
}))
);
Note that ``e.update`` will return just the ``{ id: true }`` of the updated object. If you want to select further properties, you can wrap the update in a ``e.select`` call. This is still just a single query to the database.

.. code-block:: typescript
e.params({ id: e.uuid, title: e.optional(e.str) }, (params) => {
const updated = e.update(e.Movie, (movie) => ({
filter_single: { id: params.id },
set: {
title: e.op(params.title, "??", movie.title),
},
}));
return e.select(updated, (movie) => ({
title: movie.title,
}));
});
Updating links
^^^^^^^^^^^^^^
Expand Down

0 comments on commit 6fd983f

Please sign in to comment.