Skip to content

Conversation

@holocron
Copy link

@holocron holocron commented Apr 4, 2017

MS SQL doesn't support RegExps, so the idea was to have opportunity to have "like" options for odata functions contains, startswith and endswith.

MS SQL doesn't support RegExps, so the idea was to have opportunity to have "like" options for odata functions contains, startswith and endswith.
@pofider
Copy link
Owner

pofider commented Apr 4, 2017

Thank you for your effort. I'm trying to remember this repository. :)
It seems that this filter.js file transforms mongo like queries into sql.
Such queries could include RegExp, but this is not supported in sql.
So you propose to introduce a new properietary attribute like.
I don't see this as a good way, because I wan't to be database agnostic in the libs I use this.

Wouldn't it be better to try to support regexp at least partially?

function eq (q, table, el, obj, op, type) {   
  if (obj instanceof RegExp) {
    var pattern = obj + ''  
    return q[op](table[el].like('%' + pattern.substring(1, pattern.length - 1) + '%'))
  }

  if (type.isPrimitive) {    
    return q[op](table[el].equals(obj))
  } else {    
    return q[op](table[el].like('%' + obj + '%'))
  }
}

This would make many common queries working

{ name: /somepart/ }

@holocron
Copy link
Author

holocron commented Apr 4, 2017

Hello, thanks for your answer!
well, on one hand contains case will work. but startswith and endswith won't.
BR,
Denis

@pofider
Copy link
Owner

pofider commented Apr 4, 2017

Yes, maybe it could be improved to support it and use % based on the occurrence of ^ and $ in regexp.
It will never support full regexp, but we could potentially reach the point it quite safely recognizes and apply regexps for startsWith and endsWith?

@holocron
Copy link
Author

holocron commented Apr 4, 2017

I understand it never will support it... let's try at least 👍

update: may be it's easier to convert to RegExp later on DB specific layer? at least there will be no need to parse it back

BR,
Denis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants