syncano-node icon indicating copy to clipboard operation
syncano-node copied to clipboard

Method: increment

Open Idered opened this issue 8 years ago • 8 comments

data.posts.increment('votes') // Increment by 1
data.posts.where('id', 10).increment('votes', 13) // Increment by 13

Idered avatar Nov 09 '17 10:11 Idered

@mkucharz should I also add alias inc?

data.posts.inc('votes')
data.posts.increment('votes')

Idered avatar Dec 20 '17 15:12 Idered

@Idered I think we can stay with just increment for now, for the better code readability :)

mkucharz avatar Dec 21 '17 08:12 mkucharz

@23doors

Sending PATCH request to this url with {"field_name": {"_increment": 1}} works fine

https://api.syncano.rocks/v2/instances/late-hill-3922/classes/posts/objects/:object_id/

Would it be possible to handle increment for multiple objects?

https://api.syncano.rocks/v2/instances/late-hill-3922/classes/posts/objects/

Idered avatar Dec 21 '17 09:12 Idered

@Idered you mean update multiple objects? If so - nope. 1 request updates only 1 object.

23doors avatar Dec 21 '17 11:12 23doors

Ok, then I'll implement:

  1. Using _increment property
data.posts.increment(100, 'views', 1)  // Post id, column, value
  1. First fetch all objects, then update value with batch query. NOT efficient at all but still, some users might find it useful.
data.posts.where('id', 'in', [10, 100]).increment('views')

Idered avatar Dec 21 '17 11:12 Idered

@23doors It's not very important feature but in future please think about implementing this in platform.

Idered avatar Dec 21 '17 11:12 Idered

It’s the same as with any update in REST - they are meant to update 1 object at a time. But if you update by id - you can update without fetching (but still 1 request per object)

23doors avatar Dec 21 '17 11:12 23doors

@Idered let's for now just implement basic version of single object, we will think later about some batch operations and how to solve it

mkucharz avatar Jan 24 '18 22:01 mkucharz