2017-07-31 70 views
1

我已经开始在项目中使用Cequel,我无法弄清楚如何使用Counters表。我有以下定义:Ruby - 与Cequel的柜台表

class Counter 
    include Cequel::Record 

    key :user_id, :text 
    column :text, :counter 
    column :int, :counter 
    column :boolean, :counter 
    column :timestamp, :counter 
    column :tag, :counter 
end 

,并正确地创建表:

>> DESCRIBE counters ; 

CREATE TABLE counters (
    user_id text PRIMARY KEY, 
    visits counter, 
    tweets counter 
) WITH bloom_filter_fp_chance = 0.01 
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'} 
    AND comment = '' 
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'} 
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'} 
    AND crc_check_chance = 1.0 
    AND dclocal_read_repair_chance = 0.1 
    AND default_time_to_live = 0 
    AND gc_grace_seconds = 864000 
    AND max_index_interval = 2048 
    AND memtable_flush_period_in_ms = 0 
    AND min_index_interval = 128 
    AND read_repair_chance = 0.0 
    AND speculative_retry = '99PERCENTILE'; 

但是当我尝试在控制台中创建一个记录,我得到:

INSERT statements are not allowed on counter tables, use UPDATE instead 

我可以请参阅tests有一种增量方式,但我无法找到正确的语法。任何人都有设置这个经验的经验,并可以指出我在正确的方向?

谢谢!

回答

0

在测试中找不到像Metal这样的解决方案。张贴在这里供他人使用,或者如果有人有更好的解决方案。

Cequel::Record.connection[COUNTERS_TABLE].where(record_id: record_id).increment(field_name: 1)