Subclass of patio.sql.ComplexExpression where the expression results in a text/string/varchar value in SQL.

Extends Static Properties
PropertyTypeDefault ValueDescription
likeMapObject{"truetrue": '~*', "truefalse": "~", "falsetrue": "ILIKE", "falsefalse": "LIKE"}

Like map used to by patio.sql.StringExpression.like to create the LIKE expression.

Constructor

Defined sql.js

like Static Function Public


Defined sql.js

Creates a SQL pattern match expression. left (l) is the SQL string we are matching against, and ces are the patterns we are matching. The match succeeds if any of the patterns match (SQL OR).

If a regular expression is used as a pattern, an SQL regular expression will be used, which is currently only supported on MySQL and PostgreSQL. Be aware that MySQL and PostgreSQL regular expression syntax is similar to javascript regular expression syntax, but it not exactly the same, especially for advanced regular expression features. Patio just uses the source of the regular expression verbatim as the SQL regular expression string.

If any other object is used as a regular expression, the SQL LIKE operator will be used, and should be supported by most databases.

The pattern match will be case insensitive if the last argument is a hash with a key of caseInsensitive that is not false or null. Also, if a case insensitive regular expression is used (//i), that particular pattern which will always be case insensitive.

Example
StringExpression.like(sql.a, 'a%') //=> "a" LIKE 'a%'
  StringExpression.like(sql.a, 'a%', {caseInsensitive : true}) //=> "a" ILIKE 'a%'
  StringExpression.like(sql.a, 'a%', /^a/i) //=> "a" LIKE 'a%' OR "a" ~* '^a'
        
Arguments Source
function (l){
   var args = argsToArray(arguments, 1);
   var params = likeElement(l);
   var likeMap = this.likeMap;
   var lh = params[0], lre = params[1], lci = params[2];
   var last = args[args.length - 1];
   lci = (isHash(last) ? args.pop() : {})["caseInsensitive"] ? true : lci;
   args = args.map(function (ce) {
       var r, rre, rci;
       var ceArr = likeElement(ce);
       r = ceArr[0], rre = ceArr[1], rci = ceArr[2];
       return new BooleanExpression(likeMap["" + (lre || rre) + (lci || rci)], l, r);
   }, this);
   return args.length === 1 ? args[0] : BooleanExpression.fromArgs(["OR"].concat(args));
           
}
    

Documentation generated using coddoc.