Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data Cassandra Counter update

In the spring data documentation, it says:

CassandraTemplate is the place to look for accessing functionality such as incrementing counters or ad-hoc CRUD operations.

I am trying to update a counter using the CassandraTemplate in spring-data-cassandra, but the documentation on this subject is very sparse. Is there a good example of this?

like image 440
gedanziger Avatar asked Jul 12 '26 14:07

gedanziger


1 Answers

You can also use custom @Query to update the counter value.

For example, supposing you have some repository:

public interface SomeRepository extends CassandraRepository<SomeEntity> {

@Query("update some_table SET counter=counter+1 WHERE value1 = ?0 AND value2= ?1;")
Object updateCounterValue(String value1, String value2);}

Of course you can also parametrize the value being updated.

like image 135
wsl Avatar answered Jul 14 '26 06:07

wsl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!