How to use $regexp and $iRegexp in a query
See original GitHub issueI’m trying to search an ltree column in postgresql, and followed this advice https://github.com/sequelize/sequelize/issues/11629
Steps to reproduce
I’ve whitelisted $regex and $iRegex in feathers-client.js
const {
makeServicePlugin, makeAuthPlugin, BaseModel, models, clients, FeathersVuex,
} = feathersVuex(feathersClient, {
idField: 'id',
whitelist: ['$regexp', '$iRegexp', '$options']
});
I also tried $regex and iRegex
I used the following query in the component
computed: {
findQuery() {
return {
$sort: {
id: 1
},
$limit: 100,
path: {
$regexp: 'root.*'
}
}
}
},
methods: {
...mapActions('data', {
findItems: 'find',
})
},
created: async function() {
await this.findItems({
query: this.findQuery,
})
}
I’ve also tried setting operator aliases in sequelize.js, although I understand that’s not a good idea
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
module.exports = function(app) {
const connectionString = app.get('postgres_data');
const sequelize_data = new Sequelize(connectionString, {
dialect: 'postgres',
operatorsAliases: {
$regexp: Op.regexp,
$iRegexp: Op.iRegexp
}
Expected behavior
To be able to query with $regexp and $iRegexp
Actual behavior
I get a error
type: "FeathersError",
className: "bad-request"
code: 400
data: Object { "$regexp": "root.*" }
errors: Object { }
hook: Object { type: "before", method: "find", path: "data", … }
System configuration
Tell us about the applicable parts of your setup. Postgresql 12
Module versions (especially the part that’s not working): “@feathersjs/feathers”: “^4.4.3”, “@feathersjs/socketio-client”: “^4.4.3”, “feathers-vuex”: “^3.2.0”, “socket.io-client”: “^2.3.0”, “vue”: “^2.6.11”, “vuex”: “^3.1.2”, “vuex-router-sync”: “^5.0.0”
NodeJS version: v13.3.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (8 by maintainers)
Top GitHub Comments
I hade a similar problem and I got a working solution for it. The solution steps:
Op
(Operators) from thesequelize
library. [example-model.js]operators
andwhitelist
properties of the model. [example-model.js]I hope, it helps.
I finally figured out Objection, and querying ltree columns with regex just works.
I wanted to write back with a solution for sequelize, but I never could figure it out.
Thanks for recommending feathers-objection 😃