简体   繁体   English

如何使用Orientjs(以前称为oriento)中的查询生成器从类中更新特定记录?

[英]How to update a specific record from a class using the query builder in Orientjs (previously called oriento)?

I need to update a specific record in my User class. 我需要在User类中更新特定记录。 I don't have any field with a unique index so I need to use the @rid field. 我没有任何具有唯一索引的字段,因此我需要使用@rid字段。

How can I use orientjs to update a specific record with dynamic properties ? 如何使用orientjs更新具有动态属性的特定记录?

I would like to use the query builder if possible because my updated record is in the request body. 如果可能的话,我想使用查询生成器,因为我的更新记录在请求正文中。

Here is what I've tried : 这是我尝试过的:

var id = '#' + req.param('id');

db.update('User').set(req.body).where({@rid: id}).scalar()
.then(function (total) {
console.log('updated', total, 'users');
});

It gives me a syntax error because I cannot use the @rid in the where clause : 它给了我一个语法错误,因为我不能在where子句中使用@rid:

db.update('User').set(req.body).where({@rid: id}).scalar()
                                           ^
SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/alexandre/Documents/bitbucket/rest-api/server/routes/index.js:4:12)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/alexandre/Documents/bitbucket/rest-api/server/server.js:25:14)
at Module._compile (module.js:460:26)

try 尝试

db.update(id).set(req.body).scalar()

where id is the @rid of the record you want to update id是您要更新的记录的@rid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM