问题标签 [rom-rb]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ruby - postgresql 中枚举类型列的包含过滤
我有一个 postgres 枚举create_enum(:status_type, %i[requested approved])
。我在一个带有status_type :status, null: false
.
我正在尝试像这样在红宝石中包含包含在内进行过滤root.where(requests[:status].in(*values)
:values
是一个字符串数组。
此代码返回以下错误:
Dry::Types::ConstraintError: ["requested"] violates constraints (included_in?(["requested", "approved"], ["requested"]) failed)
。
如果我通过平等过滤它,它可以正常工作。root.where(requests[:status].is('requested')
您知道我在自定义类型列中包含包含过滤的方法吗?
ruby - 使用没有列的 postgres 计算值作为 Ruby 变量
我有一个 Hanami Web 应用程序,其中一个功能是将数据库中的字符串与用户提供的字符串进行比较。为此,我使用了 postgres 扩展 pg_trgm。Ruby 中翻译后的查询条件如下所示:
.where {similarity(:content, source_text_for_lookup) > sim_score_limit}
我需要解决的问题是将计算出的相似度分数返回给 Ruby 并将其呈现给用户。然而,相似度分数不是一个属性,因为它仅在 PG 中调用该函数以比较两个字符串时才相关或应该存在。
有没有办法做到这一点?
编辑 2021
我已经对 Segment repo 中的实现进行了更改:
对此
所以我已经删除了聚合,只是现在,select_append 不再返回计算值作为段记录的一部分。为什么会发生这种变化?
输出可以在这里看到。
编辑结束
问候,塞巴斯蒂安