How to do parameterized query using slick

slick

(Riyad Parvez) #1

In Java examples of slick-alpakka it was shown Create, Update, Delete using stream. However I couldn’t find any example of using read where the SQL query is paramterized.

For example, " ```

final CompletionStage<Done> done =
    Slick.source(
            session,
            "SELECT ID, NAME FROM ALPAKKA_SLICK_JAVADSL_TEST_USERS",
            (SlickRow row) -> new User(row.nextInt(), row.nextString()))
        .log("user")
        .runWith(Sink.ignore(), materializer);

works just fine. But what if I want to parameterize the qeuery with 
`"SELECT ID, NAME FROM ALPAKKA_SLICK_JAVADSL_TEST_USERS WHERE ID = " + id;`

where the `id` will come as an input. How to achieve this using slick-alpakka?

(Enno) #2

The Alpakka Slick connector does not support reading from the database in a flow.

I assume you look for something like

Flow[Parameters, Result] slickReadFlow

which uses values in Parameters to populate query parameters.

It is not there today, but it makes sense to add such a flow.

Contributions welcome!