I think that something is not correct in what you are trying to do: Slick's run
method doesn't return Unit
and doesn't fail with an exception - as it used to in previous versions. run
now returns a Future
, so if you want to run actions in sequence you need to flatMap
the steps, or use a for-comprehension:
def init() = {
val = results for {
_ <- db.run(dal.create)
_ <- db.run(dal.stuffTable += Stuff(23, "hi"))
r <- db.run(dal.stuffTable.filter(_.serial === 23).result)
} yield r
}
I am not sure that you really need to use db.close
that way: that is actually what may be causing the error (i.e. the db is closed in concurrence with the future that runs the actual queries so the execution can't happen).
If you want to handle errors use Future
's capabilities, e.g.:
result.onFailure { case NonFatal(ex) => // do something with the exception }
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…