node-sequelize-querystring
node-sequelize-querystring copied to clipboard
SequelizeDatabaseError
I have sequelize 6.3.3 and i try used the basic example in repository README and get this error;
{
"message": "Something goes wrong",
"data": {
"name": "SequelizeDatabaseError",
"parent": {
"length": 121,
"name": "error",
"severity": "ERROR",
"code": "22P02",
"position": "167",
"file": "numutils.c",
"line": "259",
"routine": "pg_strtoint32",
"sql": "SELECT \"id\", \"name\", \"created_at\" AS \"createdAt\", \"updated_at\" AS \"updatedAt\", \"province_id\" AS \"provinceId\" FROM \"cities\" AS \"cities\" WHERE \"cities\".\"province_id\" = '[object Object]' ORDER BY \"cities\".\"id\" DESC LIMIT 10 OFFSET 0;"
},
Note the
"province_id\" = '[object Object]'
When console log to sqs.find(req.query.filter);
{ provinceId: { '$eq': '5' } }
URL: {{HOST}}/api/cities?filter=provinceId eq 5&sort=id desc
The controller:
import City from '../models/City';
import Response from '../utils/response';
import sqs from 'sequelize-querystring';
class CityController {
static async getAll(req, res) {
try {
const { rows, count } = await City.findAndCountAll({
offset: req.query.offset || 0,
limit: req.query.limit || 10,
where: req.query.filter ? sqs.find(req.query.filter) : {},
order: req.query.sort ? sqs.sort(req.query.sort) : []
});
res.json(Response.get('Cities list', rows, 200, { count }));
} catch (error) {
res.status(500).json({
message: 'Something goes wrong',
data: error
})
}
}
}