Friday 22 June 2018

How to query(express)?

Hey,so I'm about to implement querying to my API and read about some possibilities in this article. Since I'm using Sequelize.js on my backend, I tried the LHS approach, which worked out perfectly combined with the operators provided by Sequelize.jsAn example:/user?id[gt]=1&id[lt]=3 would result in (using qs)id: { gt: 1, lt: 3 } which I could simply pass in to my Sequelize.js where statement (keep in mind I used aliases, as shown here (without the $, though):User.findAll({ where: { id: { gt: 1, lt: 3 } })} This works fine.However, as described in the Sequelize.js docs, an or statement would need to look like this:User.findAll({ where: { id: { or: [1,3] } })} Is there any way I could get this by using qs?When I try to query like this:/user?id[or]=1,2 qs.parse() returns{ id: { or: '1,2' } } Although in this case I would need{ id: { or: [1,2] } } Therefore querying like this: /user?id[or]=[1,2] results in{ id: { or: '[1,2]' } } Any suggestions? Are there other ways to implement querying? I want to be able to provide as much filter, sort, query options as possible.

Submitted June 22, 2018 at 05:33PM by Fasyx

No comments:

Post a Comment