我遇到了以下问题。
我有一门课,比如 Post,看起来像:
case class Post (
id: Int,
slug: String,
title: String,
@Column("postText")
text: String,
isVisible: Boolean,
created: Timestamp,
lastUpdated: Timestamp,
published: Option[Timestamp]
) extends KeyedEntity[Int]
我的问题是从数据库中获取上一个和下一个帖子,当帖子按 已发布字段排序时。我坚持的问题是发布的字段是 Option[Timestamp]。我创建了一个这样的 Squeryl 查询:
val nextPost = from(postTable)( p =>
where((p.published > post.published) and p.isVisible === true)
select(p)
orderBy(p.published asc)
).page(0, 1)
当我查看生成的 sql 时,我看到了类似这样的内容:“... WHERE post.published > Some("....") ..."当然这会导致 SQL 查询出现语法错误。
我查看了文档,但找不到答案。我已经在考虑切换到 Slick...
更新
squeryl mysql 查询构造中有一个明确的错误。我结束了
val x : Timestamp = post.published.getOrElse(new Timestamp(0))
val nextPost = from(postTable)( p =>
where((p.published.getOrElse(new Timestamp(0)) > x) and p.isVisible === true)
select(p)
orderBy(p.published asc)
).page(0, 1)
产生查询:
Select
Post9.lastUpdated as Post9_lastUpdated,
Post9.published as Post9_published,
Post9.postText as Post9_postText,
Post9.slug as Post9_slug,
Post9.id as Post9_id,
Post9.isVisible as Post9_isVisible,
Post9.title as Post9_title,
Post9.created as Post9_created
From
Post Post9
Where
((Post9.published > 2013-08-01 14:21:25.0) and (Post9.isVisible = true))
Order By
Post9.published Asc
limit 1 offset 0
看,查询构造函数如何格式化日期......
我正在切换到 SLICK。