mswjs / data

Data modeling and relation library for testing JavaScript applications.

Home Page:https://npm.im/@mswjs/data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support sorting of records

gmanriqueUy opened this issue · comments

First of all, thanks for this library! It really eases the process of mocking a database.

While implementing pagination in my mock REST API, I couldn't find any documentation about sorting. Does that feature exists and is not documented? If not, are there any plans to add it already or I'm the first one with a use case for it?

Thanks in advance!

Hey, @gmanriqueUy. Thank you for the kind words.

Currently, there is no sorting support when paginating entities. How do you see such API being used?

I can imagine something like this:

db.user.findMany({
  where: {
    country: {
      equals: 'Spain'
    }
  },
  orderBy: [
    {
      firstName: 'asc'
    },
    {
      role: 'desc'
    }
  ],
})

I wonder how we can approach sorting of the nested properties with such API. For example, in the ordered list above, sort all user.posts by title. This is, however, a question related to the properties selection, as now the library returns the entire entity.

The orderBy option is now supported in 0.5.0.