General Syncrhonous Query Executor

26 views
Skip to first unread message

cra...@tataryn.net

unread,
Aug 1, 2016, 3:05:10 PM8/1/16
to Slick / ScalaQuery
I'm slowly porting over a data-layer from slick 2.1 to Slick 3.0.3. I want to keep things syncrhonous for now in order to maintain my repo's API (i.e. no passing back Futures just yet) One thing I need to do is convert methods that look like this:

  val query = TableQuery[ContentTable]

  def find(id: UUID): Option[ContentModel] = {
    getDatabase withSession {
      implicit session => 
        query.filter(c => c.id === id.toString).firstOption
    }
  }

to read:

  def find(id: UUID): Option[ContentModel] = {
    Await.result(getDatabase.run(query.filter(c => c.id === id.toString).result.headOption), Duration.Inf)
  }

However, instead I'd like to do something like:

  def find(id: UUID): Option[ContentModel] = {
    implict val db = getDatabase
    RepoUtils.getOption(query.filter(c => c.id === id.toString))
  }

I cannot figure out what the type signatures for a generalized RepoUtils.getOption method would look like. If this is possible, how would the RepoUtils.getOption be formulated?

Thanks,

Craig

cra...@tataryn.net

unread,
Aug 3, 2016, 12:32:19 PM8/3/16
to Slick / ScalaQuery
Just a friendly *bump*

Craig
Reply all
Reply to author
Forward
0 new messages