Search code examples
node.jsrethinkdbthinky

How can you match a field in Thinky ORM?


I am trying check if one field from a table does exists (Case In-sensitive) using Thinky ORM. Without Thinky, I can match a field just using RethinkDB simple filter-match operations:

//  This makes my variable insensitive.
let myFieldInsensitive = '(?i)^' +myFieldSensitive`enter code here`+'$';
//  Filter by matching myFieldInsensistive.
r.table('myTable').filter(r.row('myField').match(myFieldInsensitive))
 .run(myConnection, function (err, result) {
    console.log(result.length); // returns 1 if myFieldInsesitive was found
})

This code will check if the mySpecificField does exists yet in myTable (Case In-sensitive).

Now, I am trying to do the same match using Thinky, but this ORM does not support this syntax:

let myFieldInsensitive = '(?i)^' +myFieldSensitive+'$';
myModel.filter(('myField').match(myFieldInsensitive)})
  .run().then((result) => {
    console.log(result.length); // should return 1 if myFieldInsesitive was found, but this returns always empty array
})

Does anybody has idea about how can you match data in a table using Thinky?


Solution

  • Finally did it! I have included thinky.r:

    let r = thinky.r;

    Instead of writing

    myModel.filter(('myField').match(myFieldInsensitive))

    I wrote

    myModel.filter(r.row('myField').match(myFieldInsensitive))

    VOILA!