ubombi
ubombi

Reputation: 1174

How to increment counter column through Cassandra python-driver ORM

I`m using this python driver. How can i increment counter using ORM in correct way?

Maybe smth like update(counter_value__add=1) or obj.counter_value += 1?

I try to avoid this manual query UPDATE ... SET counter_value = counter_value + 1

Upvotes: 1

Views: 802

Answers (1)

ubombi
ubombi

Reputation: 1174

Resolved issue which tell, that correct way is obj.counter_value += 1 But its deprecated!

Right way is:

CounterModel(pk=pk, ck=ck).update(counter_field=1, another_counter=-2)

Also you can use update method of counter model object.

P.S.

  • There is no need to create counters, They are 0 by default.
  • You cant create counter row via .create() method.
  • You cant set any value to counter directly.

Upvotes: 2

Related Questions