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.

9me
  • 1,022
  • 9
  • 31
  • 1
    @Dário no one is replying this question. Is that question is not meaningful ? – 9me Apr 05 '15 at 19:29
  • 1
    Hi @9me, perhaps the Oriento folks don't hang out here, you can also try [Oriento gitter channel](https://gitter.im/codemix/oriento) and the [Oriento project](https://github.com/codemix/oriento). Regarding your example: `.where({id:items_ids,status:ENM.SELLING_STATUS.ACTIVE}).exec()`, you don't need an `.exec()` before a `.then(/*...*/)`. – Dário Apr 07 '15 at 13:47
  • @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 ? – 9me Apr 08 '15 at 12:12
  • @9me: did you fix it? Shouldn't you use the `scalar()` function like [in this example](https://github.com/codemix/oriento#user-content-query-builder-update-record) – Alexis N-o Jul 15 '15 at 18:16

2 Answers2

4

Try this

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

  • What about multi ids and transaction. In case of fail how can I undo this transaction ? – 9me Jun 25 '16 at 07:54
0

Have you tried following?

db.update(id).set({status:INACTIVE}).scalar()
Prashant
  • 31
  • 7
  • I did not tried it yet but my question is about mostly related with transaction based on more then one classes. – 9me Jul 22 '16 at 18:29