Increment counter columns with Cassaforte

28 views
Skip to first unread message

G Gordon Worley III

unread,
Apr 28, 2014, 6:22:39 PM4/28/14
to clojure-...@googlegroups.com
Hi.

I'm trying to figure out how I can increment a counter column using Cassaforte. I can't find any examples of how to do this, and it's also not clear to me how I could even write the query in Cassaforte's DSL short of just writing raw CQL and sending it. I've tried things like the following:

    (update :counter_cf [:counter_cf] (increment-by 1) (query/where :id someid))

but so far after multiple attempts I can't quite seem to figure out the syntax to use with update/insert when I'm not just directly setting a value and instead incrementing or decrementing.

Is there a idiomatic way to do this with Cassaforte, or do I just have to write raw CQL for now?

Alex Petrov

unread,
Apr 29, 2014, 4:53:40 AM4/29/14
to clojure-...@googlegroups.com, G Gordon Worley III
Hi,

Yes, it is quite normal, I’d say. The syntax you’ve mentioned also looks quite right.

An example from tests: 

(update :user_counters {:user_count (increment-by 5)} (where :name "user1”))
(update :user_counters {:user_count (decrement-by 5)} (where :name "user1”))
(update :user_counters {:user_count [+ 500]} (where :name "user1”))
(update :user_counters {:user_count [+ 5000000]} (where :name "user1”))
(update :user_counters {:user_count [+ 50000000000000]} (where :name "user1”))



Hope that helps 
I’ll update docs accordingly


--
You received this message because you are subscribed to the Google Groups "Cassaforte, a Clojure client for Apache Cassandra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-cassan...@googlegroups.com.
To post to this group, send email to clojure-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure-cassandra/34085515-204e-47a1-9ebe-efeb8f48a9f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

G Gordon Worley III

unread,
Apr 29, 2014, 1:44:01 PM4/29/14
to clojure-...@googlegroups.com, G Gordon Worley III
Ah, okay, I see where my issue may be now.

I currently have something like the following in my code:

    (update :user_counters {:count (increment-by 1)} (where :id user_id))

From cqlsh, I can see count increase in user_counters, but when I try to get the data using Cassaforte

    (select :user_counters (where :id "1"))

I get back:

    {:id "1", :count nil}

Even though in cqlsh I see count = 4, for example.
Reply all
Reply to author
Forward
0 new messages