Skip to content

Fragments interpolation #10

Open
Open

Description

@RobertoUa

How to inject a raw string and omit interpolation, for example I'd like for f1, f2 to be just injected as string and fun interpolate is not called for them, only for $id

val fr1 = "name, age, pic"
val fr2 = "LEFT JOIN blah .."
sql("SELECT $fr1 FROM users $fr2 WHERE id = $id")

Activity

  1. deusaquilus commented on Jun 24, 2025

    @deusaquilus
    Member

    I don't allow raw-string injection, that's point. The second I allow raw-string injection you can potentially get SQL-injection vunerabilities. Do you need completely dynamic strings?

  2. RobertoUa commented on Jun 24, 2025

    @RobertoUa
    Author

    It works in Doobie.
    Anyway, I looked at terpal-sql and I found your way to concatenate fragments.

  3. deusaquilus commented on Jun 24, 2025

    @deusaquilus
    Member

    Interesting! I didn't know doobie was fine with strings not prefixed with sql"...". I was thinking about introducing a dynamic-string splicing API but an explicit one e.g. sql("....dynamic(...)...").

  4. RobertoUa commented on Jun 25, 2025

    @RobertoUa
    Author

    ah, sorry, bad example. What I mean is just concatenating, not thinking about a specific way to do it (prefixing, wrapping, etc).
    Strings should definitely be prefixed with sql (or fr in doobie).
    Updated example.

    val fr1 = sql("name, age, pic")
    val fr2 = sql("AND name = $name") // $name should be interpolated in the final query.
    sql("SELECT $fr1 FROM users WHERE id = $id $fr2")
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions