DBIx::Class 中的设置操作

发布于 2024-11-28 19:05:45 字数 598 浏览 0 评论 0原文

使用 DBIx::Class 执行集合操作的最佳方法是什么? 我看到一种解决方案是根据我的查询创建结果源,但我的条件将由用户定义,我不知道最好的答案是否是动态创建结果源。

基本上我需要将这种类型的查询转换为 DBIC,其中 codeattr_namevalue 由用户定义:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文