users.updateMany((q) => q.where({ name: (name) => name.startsWith('J') }), {
data(user) {
user.name = user.name.toUpperCase(),
},
orderBy: {
name: 'asc',
id: 'desc',
},
})
Using an object instead of an array to configure the sorting makes the order/priority less obvious. Also, some people may prefer sorting the keys in the objects (using an ESLint plugin or manually), which would affect how the data is sorted.
Proposed approaches
Single array of objects
users.updateMany((q) => q.where({ name: (name) => name.startsWith('J') }), {
data(user) {
user.name = user.name.toUpperCase(),
},
orderBy: [
{
key: 'name',
direction: 'asc',
},
{
key: 'id',
direction: 'desc',
},
],
})
Separated arrays of keys and directions
Like in es-toolkit or Lodash.
users.updateMany((q) => q.where({ name: (name) => name.startsWith('J') }), {
data(user) {
user.name = user.name.toUpperCase(),
},
orderBy: [
[
'name',
'id',
],
[
'asc',
'desc',
],
],
})
Current approach
Using an object instead of an array to configure the sorting makes the order/priority less obvious. Also, some people may prefer sorting the keys in the objects (using an ESLint plugin or manually), which would affect how the data is sorted.
Proposed approaches
Single array of objects
Separated arrays of keys and directions
Like in es-toolkit or Lodash.