Skip to content

Make sorting configuration an array instead of an object #361

@vasilii-kovalev

Description

@vasilii-kovalev

Current approach

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',
    ],
  ],
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions