Skip to content

Latest commit

 

History

History
56 lines (48 loc) · 1.27 KB

File metadata and controls

56 lines (48 loc) · 1.27 KB

Update rows in a table

Updating rows takes two parameters. An update function that is required and an optional filter.

The update function should not mutate the row, instead it should return a new updated row. Also it should return an Object that can be serialized, just like when inserting rows. Returning anything else will result in an error.

The filter function works just like the Table::query filter. It can be an $idbID, an array of $idbID, or a custom function, or nothing in which case it will update everything.

table.update(
  row => ({
    ...row,
    column: 'updated column'
  }),
  row => row.$idbID < 3
);

// [
//   {
//     $idbID: 1,
//     column: 'updated column'
//   },
//   {
//     $idbID: 2,
//     column: 'updated column'
//   },
//   {
//     $idbID: 3,
//     column: 'column match'
//   }
// ]

An update function may return an object too, which will be merged with the original row on ::save.

table.update(() => ({column: 'override'}));

// [
//   {
//     $idbID: 1,
//     column: 'override'
//   },
//   {
//     $idbID: 2,
//     column: 'override'
//   },
//   {
//     $idbID: 3,
//     column: 'override'
//   }
// ]