MySQL RLIKE Support?

35 views
Skip to first unread message

justin hyland

unread,
Dec 12, 2015, 11:34:12 PM12/12/15
to Sequelize
I was wondering if SequelieJS still has the MySQL RLIKE support? According to the changelog, it was added back at 1.7.8, but I don't see it in the query operators, (And I also tried $rLike, which didn't work, no surprise since it wasn't listed in the operators)

Was the support for this removed at some point? And not added in the changelog? If not, a link to the documentation or even an example would be nice. 

Thanks!

justin hyland

unread,
Dec 12, 2015, 11:36:18 PM12/12/15
to Sequelize
Obviously I know about the $like, but I'm looking for a regular expression matching, not just like '%something%'

Thanks!

Mick Hansen

unread,
Dec 13, 2015, 9:17:45 AM12/13/15
to justin hyland, Sequelize
Does not look like it's supported anymore, don't recall it being removed specifically though.
A PR is welcome, simply needs a test and an addition here: https://github.com/sequelize/sequelize/blob/master/lib/dialects/abstract/query-generator.js#L1910
--
Mick Hansen
@mhansendev
mhansen.io

justin hyland

unread,
Dec 13, 2015, 1:03:50 PM12/13/15
to Sequelize, jhyl...@gmail.com
Is there a way to do it manually? But still use the query object?... Or can I create my own $rLike somehow?

Im new to NodeJS/Express/Sequelize, I'm coming from the world of PHP/Apache, but I def like what I'm seeing, and ill need regex support in the near future..

Mick Hansen

unread,
Dec 13, 2015, 1:16:40 PM12/13/15
to justin hyland, Sequelize
You can do some raw where stuff with finders yeah.
We don't currently let you plugin your own comparators at the moment, although there's a proposal for it.

justin hyland

unread,
Dec 13, 2015, 1:23:21 PM12/13/15
to Sequelize, jhyl...@gmail.com
Ok, so I can do the rlike without having to manually type the entire query string? that would suffice!

I tried looking in here and here for rlike before I created this thread, its pretty hard to follow without comments. lol But maybe thats the point!

You're saying I should submit a pull request, and code the RLIKE into the mysql query builder myself? Rather than a feature request? Just making sure

justin hyland

unread,
Dec 13, 2015, 1:27:03 PM12/13/15
to Sequelize, jhyl...@gmail.com
Wheres the documentation for the raw queries in finders? Im looking at the where query documentation, don't see it though

Mick Hansen

unread,
Dec 14, 2015, 1:58:51 AM12/14/15
to justin hyland, Sequelize
A pull request added the code is the quickest.
A raw where can be done like:

{
  col: sequelize.literal('RLIKE ...')
}

justin hyland

unread,
Dec 14, 2015, 1:02:33 PM12/14/15
to Sequelize, jhyl...@gmail.com
Awesome, Ill give that a shot, it looks like it would work. 

I'm also going to need to do a query using FIND_IN_SET, so something similar to: WHERE `hostname` LIKE 'l%01.host.ad' AND FIND_IN_SET('Apache',`applications`), and it looks like this should work for that too, correct?

Thanks!
-J

Mick Hansen

unread,
Dec 14, 2015, 5:14:25 PM12/14/15
to justin hyland, Sequelize
Should work, love to have a more elegant wait for it - but not sure we do.

justin hyland

unread,
Dec 15, 2015, 2:32:11 AM12/15/15
to Mick Hansen, Sequelize
Im really surprised there isn't a way to add your own methods or data types or query operators. I mean Sequelize is awesome, for sure, but when I start trying to use it for more advanced stuff than the typical usages, it runs into limitations, which is why im surprised there isnt a way to import features.

I really don't want to edit the sequelize code itself, because that will hinder being able to manage the versions via GIT.

justin hyland

unread,
Dec 15, 2015, 2:53:28 AM12/15/15
to Sequelize, dooms...@gmail.com
I guess it doesn't matter what I use for the key value in the where statement, where the column name should be?

Servers
    .findAll({
       
where: {
           
notes: SEQUELIZE.literal('`hostname` RLIKE "ld(web|jen)01.whatever.ad"')
       
}
   
})
   
.then( ( result ) => {
       
console.log('RESULT:', SEQUELIZE.getValues(result));
   
})
   
.catch( ( err ) => {
       
console.error('ERROR',err);
   
});
The real column name is hostname, but it looks like I can specify anything (notes in this case)

Weird o.O

Mick Hansen

unread,
Dec 15, 2015, 2:58:16 AM12/15/15
to justin hyland, Sequelize
data types are possible. query operators are in the proposal state.
we really want to make sequelize more extensible, make plugins a more commonplace thing.

Hmm, sequelize.literal might make it ignore the key, i forgot about that. You can also try using `notes: ['RAW QUERY']`
Reply all
Reply to author
Forward
0 new messages