为 Hasql 查询编码参数列表
Encoding a Parameter List for a Hasql query
我正在尝试获取 Hasql to encode a list for a "select ... where in" query. It typechecks if I use contramany
from contravariant-extras,但在运行时出现语法错误。
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 "
是否不能对参数列表进行编码?
"IN" 运算符不支持。您只能用它指定单个值(例如,IN (, , )
)。然而,根据 the docs.
,使用数组编码器和 any
和 all
Postgres 函数可以轻松实现您想要的。
有some Hasql tests showing it in action.
问题跟踪器上也有 a discussion on that subject。
我正在尝试获取 Hasql to encode a list for a "select ... where in" query. It typechecks if I use contramany
from contravariant-extras,但在运行时出现语法错误。
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 "
是否不能对参数列表进行编码?
"IN" 运算符不支持。您只能用它指定单个值(例如,IN (, , )
)。然而,根据 the docs.
any
和 all
Postgres 函数可以轻松实现您想要的。
有some Hasql tests showing it in action.
问题跟踪器上也有 a discussion on that subject。