twitchtv / node-apicalypse

The apicalypse query language client for nodejs
MIT License
81 stars 11 forks source link

.sort() for multiple columns #6

Closed summerkiflain closed 5 years ago

summerkiflain commented 5 years ago

Hi there,

How can I sort games data by multiple column, sometimes records start appearing in random order if the timestamp is same for multiple records, e.g, first_release_date is repeating for multiple records, but fetching next 5 or 10 records using offset, same records appearing on different places, so I want to sort by both first_release_date and id of the record, so that same games appear on the exactly same place from the previous query.

I have tried using .sort('first_release_date') and sort('id', 'desc') but it responds with an error.

    apicalypse(requestOptions)
      .fields('name, first_release_date')
      .limit(5)
      .offset(1)
      .sort(`first_release_date`)
      .sort(`id`, 'desc')
      .where(`first_release_date > ${moment().unix()}`)
      .request(`/games`)
      .then(response => {
        console.log('@@@', response.data);
        res.json(response.data);
      })
      .catch(err => {
        console.error('###', err);
        res.status(err.response.status).send({ error: err.message});
      });

Thanks.

krazyjakee commented 5 years ago

Hi there.

This is not currently (it's in the backlog) supported by the API so further sorting will need to be done in the client.

On Tue, Mar 5, 2019, 12:49 Summer Kiflain notifications@github.com wrote:

Hi there,

How can I sort games data by multiple column, sometimes records start appearing in random order if the timestamp is same for multiple records, e.g, first_release_date is repeating for multiple records, but fetching next 5 or 10 records using offset, same records appearing on different places, so I want to sort by both first_release_date and id of the record, so that same games appear on the exactly same place from the previous query.

I have tried using .sort('first_release_date') and sort('id', 'desc') but it responds with an error.

apicalypse(requestOptions)
  .fields('name, first_release_date')
  .limit(5)
  .offset(1)
  .sort(`first_release_date`)
  .sort(`id`, 'desc')
  .where(`first_release_date > ${moment().unix()}`)
  .request(`/games`)
  .then(response => {
    console.log('@@@', response.data);
    res.json(response.data);
  })
  .catch(err => {
    console.error('###', err);
    res.status(err.response.status).send({ error: err.message});
  });

Thanks.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/igdb/node-apicalypse/issues/6, or mute the thread https://github.com/notifications/unsubscribe-auth/AAmDZ1voOh05nyoeQmWFeSs4LrJ2d28Rks5vTmfWgaJpZM4beh96 .

summerkiflain commented 5 years ago

Hi @krazyjakee, Thanks for replying so quickly, sorting in the client side wont solve the issue. because it would require fetching all the required data on first load and then sort it by id, otherwise fetching data with pagination will remain an issue, because it seemingly randomize the records on next offset calls.

krazyjakee commented 5 years ago

Since this is an issue with the IGDB api and not the node wrapper, I will close this and forward your bug report to the appropriate team.