如何在sqlu查询中绑定Seq [String]参数?

时间:2015-12-28 02:00:04

标签: postgresql scala slick

如何在Seq[String]查询中绑定sqlu参数?

我想将字符串容器传递给查询。我的查询在普通的sql

中看起来像这样
update public.users set topic_ids = array_append(topic_ids, 'one') 
where id = E'\\x55ef630a590801000126136e' and ('{one}' && topic_ids) = true

我尝试了以下版本的代码

val userId: ObjectId = ... // I have SetParameter[ObjectId] for it
val topicId: String = "blah"

// Fails with: org.postgresql.util.PSQLException: The column index is out of range: 3, number of columns: 2.
sqlu"update public.users set topic_ids = array_append(topic_ids, $topicId::text) where id = $userId && ('$topicId' && topic_ids) = true"

// Fails with "could not find implicit value for parameter e: slick.jdbc.SetParameter[Seq[String]]"
sqlu"update public.users set topic_ids = array_append(topic_ids, $topicId::text) where id = $userId && (${Seq(topicId)}::text[] && topic_ids) = true"

// Fails with "org.postgresql.util.PSQLException: ERROR: operator does not exist: bytea && boolean"
sqlu"update public.users set topic_ids = array_append(topic_ids, $topicId::text) where id = $userId && ('{#$topicId}' && topic_ids) = true"

我会创建SetParameter[Seq[String]],但没有设置数组的setter。

我该如何实现?

0 个答案:

没有答案