drhs13583567608 2019-01-09 15:26
浏览 84

如何检查是否应用了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!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料