# Special Alpakka Slick Flow streaming elements off of a SELECT

**URL:** <https://discuss.akka.io/t/special-alpakka-slick-flow-streaming-elements-off-of-a-select/1535>\
**Category:** Akka Streams & Alpakka\
**Created:** [July 11, 2018, 6:57pm UTC](https://discuss.akka.io/t/special-alpakka-slick-flow-streaming-elements-off-of-a-select/1535 "2018-07-11T18:57:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![max8github](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/max8github/32/681_2.png) [@max8github](https://discuss.akka.io/u/max8github)\
**Post date:** [July 11, 2018, 6:57pm UTC](https://discuss.akka.io/t/special-alpakka-slick-flow-streaming-elements-off-of-a-select/1535/1 "2018-07-11T18:57:59Z")

</div>

After reading about the Alpakka’s Slick adapter, i was not able to figure out how to stream elements off of a SELECT in a Flow.  
It is easy to do with a Source:

```auto
Slick.source(sql"SELECT ID, NAME FROM USERS".as[User])

```

which will emit one User element at a time.  
Not so easy to me with a Flow that takes some element, issues a SELECT query internally and then emits the result of that SELECT one by one.  
(For example, say the input element to the Flow is an Int, 100, and the SELECT is something like ‘SELECT \* FROM USERS LIMIT 100’)

The closest Flow operation i see in Alpakka resembling what i need is `Slick.flowWithPassThrough`, but that seems to be forcing me to

> `Slick.flowWithPassThrough[Int, Seq[User]]`

and not something like

```auto
Slick.flowWithPassThrough[Int, User]

```

with `User` and not `Seq[User]`.

Of course, i can add a downstream stage that flattens the sequence resulting from the SELECT stage upstream, but i was trying to avoid that.  
Did i miss something obvious in the documentation or API, or do i have to write a special GraphStage (Flow)?

---

<div class="post-metadata">

**Author:** ![2m](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/2m/32/88_2.png) [@2m](https://discuss.akka.io/u/2m)\
**Post date:** [July 12, 2018, 11:03am UTC](https://discuss.akka.io/t/special-alpakka-slick-flow-streaming-elements-off-of-a-select/1535/2 "2018-07-12T11:03:58Z")

</div>

I am glad that you found Alpakka Slick connector interesting.

It looks like you could use the [`flatMapConcat`](https://doc.akka.io/docs/akka/current/stream/operators/Source-or-Flow/flatMapConcat.html#flatmapconcat) operator here.

```scala
val flow: Flow[Int, User, NotUsed] =
  Flow[Int].flatMapConcat(limit =>
    Slick.source(sql"SELECT ID, NAME FROM USERS, LIMIT $limit".as[User]))

```
