S.Karthik
S.Karthik

Reputation: 1389

Akka-http streaming using Slick 3.0 Databasepublisher

I am using slick 3.0 and have a databasepublisher object as

def getAsStream = db.stream[Entity](tblquery.result)

I am using akka-http for rest layer as follows,

val route = 
path("stream"){
 get {
    complete { // how to stream from here  }
  }
}

How can I use this databasepublisher object, to transform(json) and stream each row to the client. Please help.

Upvotes: 8

Views: 1015

Answers (1)

S.Karthik
S.Karthik

Reputation: 1389

I finally doing something like this, do not know whether its right way,

 complete {
       val source = Source(repository.getAsStream).map(a => ChunkStreamPart(a.asJson))
       HttpResponse(entity = HttpEntity.Chunked(MediaTypes.`application/json`, source))
         }

Upvotes: 2

Related Questions