我试图让一些看似微不足道的工作,但我不能让它编译。我无法将部分SQL存储在本地变量中:
val sql = select.from(Post as p).where.eq(p.id, id)
if (lock)
sql.forUpdate
else
sql
抱怨
Error:(44, 17) type mismatch;
found : scalikejdbc.PagingSQLBuilder[Nothing]
required: scalikejdbc.SQLBuilder[A]
Note: Nothing <: A, but trait SQLBuilder is invariant in type A.
You may wish to define A as +A instead. (SLS 4.5)
withSQL {
即使这不起作用:
withSQL {
if (lock)
select.from(Post as p).where.eq(p.id, id).forUpdate
else
select.from(Post as p).where.eq(p.id, id)
}
有人知道如何解决这个问题吗?