本文介绍了使用后端特定运算符的持久性示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在持久化中做一个LIKE查询,我正在使用sqlite。 yesod书给出了一个使用原始SQL来做的例子,但是说:

我无法但找到一个例子。有人会举例说明使用像LIKE这样的特定运算符与 selectList 或类似的东西吗?



Thanks!

解决方案

我知道我以前用过它,但我不记得在哪里。无论如何,一个简单的例子(不是GHC检查,道歉)将是:
$ b $ pre $ selectList [过滤PersonName(Left $ PersistText Michael%)(BackendSpecificFilterILIKE)] []

显然你可以创建一些辅助函数,例如:

  icontains字段val =过滤字段(Left $ PersistText $ T.concat [%,val,% ])(BackendSpecificFilterILIKE)
selectList [Personname`icontains`Michael] []


I would like to do a LIKE query in persistent, I'm using sqlite. The yesod book gives an example of using raw SQL to do it, but says:

I couldn't find an example of that, though. Would somebody have an example of what it would mean to use a specific operator like LIKE with selectList or something equivalent?

Thanks!

解决方案

I know I've used it before, but I can't remember where. Anyway, a simple example (not GHC-checked, apologies) would be:

selectList [Filter PersonName (Left $ PersistText "%Michael%") (BackendSpecificFilter "ILIKE")] []

Obviously you can create some helper function, e.g.:

icontains field val = Filter field (Left $ PersistText $ T.concat ["%", val, "%"]) (BackendSpecificFilter "ILIKE")
selectList [Personname `icontains` "Michael"] []

这篇关于使用后端特定运算符的持久性示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 20:59