DBIx::Class 中的设置操作
使用 DBIx::Class 执行集合操作的最佳方法是什么? 我看到一种解决方案是根据我的查询创建结果源,但我的条件将由用户定义,我不知道最好的答案是否是动态创建结果源。
基本上我需要将这种类型的查询转换为 DBIC,其中 code
、attr_name
和 value
由用户定义:
SELECT pid FROM product WHERE code = 48
INTERSECT
(
( SELECT pid FROM attr WHERE attr_name = 'color' AND value = 'blue'
INTERSECT
SELECT pid FROM attr WHERE attr_name = 'size' AND value = 'big'
)
UNION
( SELECT pid FROM attr WHERE attr_name = 'color' AND value = 'green'
INTERSECT
SELECT pid FROM attr WHERE attr_name = 'size' AND value = 'small'
)
)
What is the best way to perform set operations using DBIx::Class?
I saw that one solution would be to create a Result Source based on my query, but my conditions will be defined by the user and I don know if the best answer is to create the result source on the fly.
Basically i need to translate this type of query to DBIC where code
, attr_name
and value
is defined by the user:
SELECT pid FROM product WHERE code = 48
INTERSECT
(
( SELECT pid FROM attr WHERE attr_name = 'color' AND value = 'blue'
INTERSECT
SELECT pid FROM attr WHERE attr_name = 'size' AND value = 'big'
)
UNION
( SELECT pid FROM attr WHERE attr_name = 'color' AND value = 'green'
INTERSECT
SELECT pid FROM attr WHERE attr_name = 'size' AND value = 'small'
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以 DBIx::Class::Helper::ResultSet ::SetOperations 是您所需要的吗?
Could DBIx::Class::Helper::ResultSet::SetOperations be what you need?