ruby sequel 访问 json 字段
ruby sequel access json field
我有以下架构:
Column | Type | Modifiers
---------+-----------------------------+------------------------
id | text | not null
data | json | not null
created | timestamp without time zone | not null default now()
如果我打开 psql,我可以 运行 查询。
select id, data->'amount' as amount from plans;
但是rubysequel
gem毁了它。
puts $db.run("select id, data->'amount' as amount from plans")
怎么了?
需要#literal
方法。
$db.run("select id, data -> #{ $db.literal('amount') } as amount from plans")
我有以下架构:
Column | Type | Modifiers
---------+-----------------------------+------------------------
id | text | not null
data | json | not null
created | timestamp without time zone | not null default now()
如果我打开 psql,我可以 运行 查询。
select id, data->'amount' as amount from plans;
但是rubysequel
gem毁了它。
puts $db.run("select id, data->'amount' as amount from plans")
怎么了?
需要#literal
方法。
$db.run("select id, data -> #{ $db.literal('amount') } as amount from plans")