如何检查是否应用了CQL查询

I have an API Server written on golang in a front of Cassandra, so I use gocql as driver. What I want is to return an error if someone tries to create duplicated entries in Cassandra, so I need not only idempotent operation (which could be achieved via if not exists clause), but also somehow to know if query was applied or not. Preliminary request like SELECT primary_keys FROM TABLE WHERE primary_keys = blah LIMIT 1 is not an option as INSERT operation should be atomic.

When I run an example below in cqlsh Cassandra tells if query is applied:

    cqlsh> create table tests.demo (
       ... uuid text PRIMARY KEY,
       ... data text
       ... );

    cqlsh> insert into tests.demo (uuid, data) values ('test', 'data') if not exists;

     applied
    -----------
      True 

    cqlsh> insert into tests.demo (uuid, data) values ('test', 'data') if not exists;

       applied | uuid | data
    -----------+------+------
         False | test | data

Is there any option to achieve the same with gocql since query.Exec() returns only error?

Thank you!

douwen3836
douwen3836 谢谢你的提示。我设法用.ScanCAS()解决了这个问题。
一年多之前 回复
drfkl66684
drfkl66684 您可以尝试使用.Scan而不是.Exec,然后查找结果的应用列-应该只有一行数据...
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问