SELECT and UPDATE multiple records in oriento / orientjs and transaction in waterline
Asked Answered
S

2

54

How can I select or update multiple records in oriento? Like in waterline we can

offersModel.update({id:items_ids,status:INACTIVE},{status:ACTIVE})

But in waterline transaction is not available. So I want to use :

var db = offersModel.getDB();
var trans = db.begin();
    trans.update('offers')
         .set({status:INACTIVE})
         .where({id:items_ids,status:ENM.SELLING_STATUS.ACTIVE})//.exec()
         .then(function(offers){ 
            if  (offers.length != items_ids.length) {trans.rollback(); /* send error here*/} 
            else trans.commit();
         })

Thanks.

Shelve answered 4/4, 2015 at 12:37 Comment(4)
@Dário no one is replying this question. Is that question is not meaningful ?Shelve
Hi @9me, perhaps the Oriento folks don't hang out here, you can also try Oriento gitter channel and the Oriento project. Regarding your example: .where({id:items_ids,status:ENM.SELLING_STATUS.ACTIVE}).exec(), you don't need an .exec() before a .then(/*...*/).Fenrir
@Dário Thank you for reply. my sorry I can not explain my use-case. My use-case is begin() then update items then **if any item is missing** rollback() else commit() How can I perform this transaction ?Shelve
@9me: did you fix it? Shouldn't you use the scalar() function like in this exampleHyades
E
4

Try this

db.update(id).set({status:INACTIVE}).scalar()

Exchange answered 24/6, 2016 at 10:21 Comment(1)
What about multi ids and transaction. In case of fail how can I undo this transaction ?Shelve
S
0

Have you tried following?

db.update(id).set({status:INACTIVE}).scalar()
Sybarite answered 27/5, 2016 at 12:7 Comment(1)
I did not tried it yet but my question is about mostly related with transaction based on more then one classes.Shelve

© 2022 - 2024 — McMap. All rights reserved.