[英]Encoding a Parameter List for a Hasql query
I'm trying to get Hasql to encode a list for a "select ... where in" query.我试图让Hasql为“select ... where in”查询编码一个列表。 It typechecks if I use
contramany
from contravariant-extras , but I get a syntax error at runtime.它会检查我是否使用
contramany
-extras 中的contramany
,但在运行时出现语法错误。
import qualified Database.Encoders as E
import Contravariant.Extras
getTeamMembership :: Query [TeamId] [(TeamId, EmployeeId)]
getTeamMembership = statement q enc def True
where
enc = contramany (E.value E.teamId)
q = "select workteam, employee \
\from workteam_employee where workteam in $1"
Is it not possible to encode a parameter list?不能对参数列表进行编码吗?
The "IN" operator does not support that. “IN”运算符不支持。 You can only specify the individual values with it (eg,
IN ($1, $2, $3)
).您只能用它指定单个值(例如,
IN ($1, $2, $3)
)。 However what you want is easily achievable with the Array encoder and any
and all
Postgres functions, as per the docs .但是,根据文档,使用 Array 编码器和
any
和all
Postgres 函数可以轻松实现您想要的。
There are some Hasql tests showing it in action .有一些 Hasql 测试显示它正在运行。
There's also been a discussion on that subject on the issue tracker.在问题跟踪器上也有关于该主题的讨论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.