Ruby - 用 Cequel 反击 table

Ruby - Counter table with Cequel

我已经开始在一个项目中使用 Cequel,但我不知道如何使用计数器 table。我有以下定义:

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

并正确创建 table:

>> 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 中看到有一种方法可以递增,但我找不到正确的语法。任何人都有设置它的经验并且可以指出正确的方向吗?

谢谢!

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

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