Reputation: 1389
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
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