0

I am not able to reuse ScalikeJDBC caller's session in a method that returns Akka stream.

I am trying to write a class for database access that returns Source for use in Akka streaming application.

The following code works:

def retrieveMembers(): Source[Member, NotUsed] =
    val publisher: DatabasePublisher[Member] =  DB readOnlyStream { Member.streamAll }
    Source.fromPublisher(publisher)

However, this method creates its own transaction, so I wanted to follow up the recommendations here: AutoSession and changed the method to:

def retrieveMembers()(implicit session: DBSession = AutoSession): Source[Member, NotUsed] =
    val publisher: DatabasePublisher[Member] =  session readOnlyStream { Member.streamAll }
    Source.fromPublisher(publisher)

But, this does not work, because readOnlyStream is not defined for DBSession, only for DB.

How can I change my method so that it can reuse the caller transaction?

Thanks in advance!

Gastón Schabas
  • 2,153
  • 1
  • 10
  • 17

0 Answers0