0

我正在尝试做一些看似微不足道的工作,但我无法让它编译。我无法将部分 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)
}

有人知道如何解决这个问题吗?

4

0 回答 0