Search
ctrl/
Ask AI
Light
Dark
System

Update

Update objects with the e.update function.

Copy
e.update(e.Movie, () => ({
  filter_single: { title: "Avengers 4" },
  set: {
    title: "Avengers: Endgame"
  }
}))

You can reference the current value of the object’s properties.

Copy
e.update(e.Movie, (movie) => ({
  filter: e.op(movie.title[0], '=', ' '),
  set: {
    title: e.str_trim(movie.title)
  }
}))

You can conditionally update a property by using an optional parameter and the coalescing infix operator.

Copy
e.params({ id: e.uuid, title: e.optional(e.str) }, (params) =>
  e.update(e.Movie, (movie) => ({
    filter_single: { id: params.id },
    set: {
      title: e.op(params.title, "??", movie.title),
    }
  }))
);

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.

Copy
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,
  }));
});

You can use a for loop to perform bulk updates.