Scala 羽毛笔-不能标记非标量提升

Scala 羽毛笔-不能标记非标量提升,scala,quill.io,Scala,Quill.io,我目前遇到这个错误,我不太明白为什么: 宏扩展期间出现异常:java.lang.IllegalStateException:无法标记非标量提升。AgentService.this.agentsByOrganizationid.id 在进行查询之前,是否需要将ID转换为Long?我希望能够使用特定的Id类,但我是Scala新手,不确定这是否可行。此外,并非所有查询都会失败。例如,delete可以工作,即使它也被传递一个AgentId。而FindByorOrganization方法不起作用。传递Ag

我目前遇到这个错误,我不太明白为什么:

宏扩展期间出现异常:java.lang.IllegalStateException:无法标记非标量提升。AgentService.this.agentsByOrganizationid.id

在进行查询之前,是否需要将ID转换为Long?我希望能够使用特定的Id类,但我是Scala新手,不确定这是否可行。此外,并非所有查询都会失败。例如,delete可以工作,即使它也被传递一个AgentId。而FindByorOrganization方法不起作用。传递AgentId的其他方法也显示与findByOrganization相同的错误

型号:

case class AgentId(value: Long) extends AnyVal
case class OrganizationId(value: Long) extends AnyVal
case class Agent(
                  id: AgentId
                  , identifier: String
                  , organizationId: OrganizationId
                  , createdAt: LocalDateTime
                  , updatedAt: LocalDateTime
                )
服务:

class AgentService(implicit val ex: ExecutionContext, val ctx: DBContext)
  extends AgentsRepository {
  import ctx._

  def listByOrganization(id: OrganizationId): List[Agent] =
    ctx.run(agentsByOrganization(id)) // this returns the error

  def delete(agent: RichAgent): Unit = {
    ctx.run(deleteAgent(agent)) // this doesn't
  }
}
存储库:

trait AgentsRepository extends Repository {
  import ctx._

  def agentsByOrganization(id: OrganizationId) = quote { // error
    query[Agent].filter(_.organizationId == lift(id))
  }

  def agentById(id: AgentId) = quote {
    query[Agent].filter(_.id == lift(id))
  }

  def deleteAgent(agent: Agent) = quote { agentById(agent.id).delete }
}
分贝


我见过这个,但它似乎是特定的选择。下面是一个。

不太确定发生了什么,但现在它正在工作:

    case class AgentId(value: Long) extends AnyVal
case class Agent(
                  id: AgentId
                  , identifier: String
                  , organizationId: OrganizationId
                  , createdAt: LocalDateTime
                  , updatedAt: LocalDateTime
                )
case class RichAgent(
                  id: AgentId
                  , identifier: String
                  , organization: Organization
                )
服务

class AgentService(implicit val ex: ExecutionContext, val ctx: DBContext)
  extends AgentsRepository {
  import ctx._

  def listByOrganization(id: OrganizationId): List[Agent] =
    ctx.run(agentsByOrganization(id))

  def delete(agent: Agent): AgentId = {
    AgentId(ctx.run(deleteAgent(agent.id)))
  }
}
存储库

trait AgentsRepository extends Repository {
  import ctx._

  val agents = quote {
    query[Agent]
  }

  def agentsByOrganization(id: OrganizationId) = quote {
    agents.filter(_.organizationId == lift(id))
  }

  def agentById(id: AgentId) = quote {
    agents.filter(_.id == lift(id))
  }

  def deleteAgent(agentId: AgentId) = quote { agentById(agentId).delete }
}
分贝


您还可以指定如何定义DBContext和最重要的ctx,即导入ctx中使用的ctx?如果我使用val ctx=new H2JdbcContextSnakeCase,您的代码似乎可以为我编译,ctx@SergGr添加了DBContext。您的代码编译失败是真的吗?您的scastie代码段失败的时间要早得多,因此它不是一个错误。如果我尝试在本地环境中扩展它,它似乎可以为我编译。我正在使用io.getquill%%quill jdbc%2.3.1。不确定还有什么地方可能会有不同。它确实无法编译,在我进行其他更改时,它最终编译了。
trait AgentsRepository extends Repository {
  import ctx._

  val agents = quote {
    query[Agent]
  }

  def agentsByOrganization(id: OrganizationId) = quote {
    agents.filter(_.organizationId == lift(id))
  }

  def agentById(id: AgentId) = quote {
    agents.filter(_.id == lift(id))
  }

  def deleteAgent(agentId: AgentId) = quote { agentById(agentId).delete }
}
object db {
  class DBContext(config: String) extends PostgresJdbcContext(SnakeCase, config)

  trait Repository {
    val ctx: DBContext
  }
}