如何匹配 Thinky ORM 中的字段?
How can you match a field in Thinky ORM?
我正在尝试使用 Thinky ORM 检查 table 中的一个字段是否存在(不区分大小写)。没有 Thinky,我可以 匹配 一个字段,只需使用 RethinkDB 简单的 filter-match 操作:
// 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
})
此代码将检查 mySpecificField 是否存在于 myTable 中(区分大小写)。
现在,我正在尝试使用 Thinky 来做同样的 match,但是这个 ORM 不支持这种语法:
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
})
有人知道如何使用 Thinky 匹配 中的 table 数据吗?
终于做到了!我已经包括 thinky.r:
let r = thinky.r;
而不是写作
myModel.filter(('myField').match(myFieldInsensitive))
我写了
myModel.filter(r.row('myField').match(myFieldInsensitive))
瞧瞧!
我正在尝试使用 Thinky ORM 检查 table 中的一个字段是否存在(不区分大小写)。没有 Thinky,我可以 匹配 一个字段,只需使用 RethinkDB 简单的 filter-match 操作:
// 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
})
此代码将检查 mySpecificField 是否存在于 myTable 中(区分大小写)。
现在,我正在尝试使用 Thinky 来做同样的 match,但是这个 ORM 不支持这种语法:
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
})
有人知道如何使用 Thinky 匹配 中的 table 数据吗?
终于做到了!我已经包括 thinky.r:
let r = thinky.r;
而不是写作
myModel.filter(('myField').match(myFieldInsensitive))
我写了
myModel.filter(r.row('myField').match(myFieldInsensitive))
瞧瞧!