1

I have a mySQL database table t1 with a bigint field called filter which I need to 'and' to a given query parameter in order to filter out entries.

table t1:

filter bigint unsigned
info   varchar(200) 

As a pure mySQL statement my query would be this:

SELECT info FROM t1 WHERE (filter & 34603933) = filter;

Of course the number 34603933 is a parameter and changes from query to query.

The question is, if loopbackjs supports such a calculus in the where condition. Can someone point me the way, or if it is not possible suggest a workaround?

In the documentation http://docs.strongloop.com/display/public/LB/Where+filter I did not see a possibility to do this, but somehow I can't really believe it, since using references to columns values in the right side of a where comparison is nothing unusual, right?

luksch
  • 11,497
  • 6
  • 38
  • 53

1 Answers1

1

I do not believe loopback has this support built-in and bitwise and operations are not that widespread (in my experience). You might try the raw SQL interface:

var mysqlDS = app.dataSources.mysqlDS;
var bitWiseAndValue = 34603933;
mysqlDS.connector.query('SELECT info FROM t1 WHERE (filter & '+bitWiseAndValue+') = filter', function(err) {
  if (err) {return console.log(err);}

  // success actions

});
notbrain
  • 3,366
  • 2
  • 32
  • 42
  • Thx, I will try this. But of course the problem is not limited to bitwise operations, but affects all queries where you want to use a column value on the right hand side of a where expression. – luksch Jun 05 '15 at 17:08