sql到slick的转换

qcbq4gxm  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(403)

我正在将sql查询转换为slick dsl。我被时间戳转换困住了。我的sql查询是:

Select isActive from users where create_time <= TIMESTAMPADD(MINUTE,
${AUTO_EXPIRY_DB_DAYS * HOURS_24 * MINUTES_60}, sysdate())
and isVerified=false;

如何为同样的问题编写一个巧妙的查询?

userQuery.filter(user => user.isVerified === FALSE && user.createdDate
<= ?????).map(_.isActive)
nukf8bse

nukf8bse1#

看一看标量数据库函数光滑的文档。我想这应该行得通:

val sysdate = SimpleLiteral[java.sql.Timestamp]("sysdate")
val timestampAdd = SimpleFunction.ternary[String, Int, java.sql.Timestamp, java.sql.Timestamp]("TIMESTAMPADD")

userQuery
    .filter(user => user.isVerified === FALSE 
                && user.createdDate <= timestampAdd("MINUTE", 20, sysdate))
    .map(_.isActive)

相关问题