Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Alexandre Roba
      override def getPaymentErrorsByBookingIds(bookingIds: Seq[UUID]): DBIO[Seq[(UUID, Seq[PaymentError])]] =
          .filter(b => b.bookingId inSet bookingIds)
          .map {
            case (bookingId, errors) => bookingId -> errors
    The Payment Error table looks like:
    trait PaymentErrorTable {
      class PaymentErrors(tag: Tag) extends Table[PaymentError](tag, "payment_error") {
        def newIdWhenInserting: UUID = UUID.randomUUID()
        def currentWhenInserting = new Timestamp((new Date).getTime)
        def id              = column[UUID]("id", O.Default(newIdWhenInserting), O.PrimaryKey)
        def bookingId       = column[UUID]("booking_id")
        def paymentMethodId = column[String]("payment_method_id")
        def error           = column[String]("error")
        def amount          = column[BigDecimal]("amount")
        def currency        = column[Currency]("currency")
        def createdAt       = column[Timestamp]("created_at", O.Default(currentWhenInserting))
        def * =
          ) <> ((PaymentError.apply _).tupled, PaymentError.unapply)
      protected val paymentErrors = TableQuery[PaymentErrors]
    Unfortunattely when compiling I'm getting the following error:
    No matching Shape found.
    Slick does not know how to map the given types.
    Possible causes: T in Table[T] does not match your * projection,
     you use an unsupported type in a Query (e.g. scala List),
     or you forgot to import a driver api into scope.
      Required level: slick.lifted.FlatShapeLevel
         Source type: (slick.lifted.Rep[java.util.UUID], slick.lifted.Query[JdbcPaymentErrorStorage.this.PaymentErrors,booking.PaymentError,[+A]Seq[A]])
       Unpacked type: T
         Packed type: G
          .map {
    Alexandre Roba
    I've got a feeling that groupbycan only be used with aggregate functions...
    Richard Dallaway
    Yeah, I'd do the aggregation into (what is effective, kind of) a map client-side. You could totally count the errors but I don't think you can aggregate like that. (I'm not sure what the SQL would be to return a row containing an id and a list of errors... although there's probably a way to do it in Postgres: it seems to have all the toys 😍 )
    Hi, In slick we generally mention the database credentials in application.conf. But is there any way we can configure these credentials through code? Basically I wanted to retrieve the DB credentials from aws secret manager and then configure them using slick. How should I proceed?
    @vyshnavi-adusumelli have you tried creating a scala object to configure hilaki data source, it basically takes all the params and you could import it from anywhere you want? Then use JdbcBackend.Database.forDataSource to create a db object.
    1 reply
    Konstantin Simeonov

    Hi everyone, I'm using plainsql slick queries and I'm running into the following issue:

    Caused by: org.postgresql.util.PSQLException: ERROR: column "expiry_date" is of type timestamp without time zone but expression is of type character varying

    The column in question is of type timestamp with timezone.

    Here's how I build my query:

        val query = sqlu"""INSERT INTO "offers"
        VALUES (
                  ${new Timestamp(Instant.now.toEpochMilli)},
                  ${new Timestamp(c.expiryDate)},
                  ${new Timestamp(c.startAt)},
                  ${new Timestamp(c.endAt)},
    2 replies
    Renato Cavalcanti
    Hi @/all
    Slick v3.3.3 is out: https://github.com/slick/slick/releases/tag/v3.3.3
    1 reply
    Georgios Larkou
    Case.If(aquery.length>0) Then bquery else cquery
    It seems that the following does not work, what is the suggested way to perform different queries based on the length of the previous one?
    2 replies
    Antoine Doeraene
    @renatocaval thanks! Are there any open points where it could be a good point to jump in and provide some help?
    18 replies
    Hello can someone show me the full slick reference.conf for postgres db with connection pool. It seems the documentation is a bit all over the place for me.
    1 reply
    Blaž Marinović

    hi all! :) I'm having a problem with values interpolation in raw SQL. This works on PostgreSQL CLI:

    select file_name from (values ('file1'), ('file2'), ('file3')) AS t (file_name) except select file_name from processed_s3_files;

    I was expecting this to work:

    val fileNamesAsValues = fileNames.map(fn => s"('$fn')").mkString(", ")
    sql"""select "file_name" from (values $fileNamesAsValues) AS t ("file_name") except select "file_name" from "processed_s3_files"""".as[String]

    but I get org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"

    Antoine Doeraene
    You need # in front of the $. It's documented here http://scala-slick.org/doc/3.3.2/sql.html
    David Leonhart

    Hi, I am having problems with using Instant with the newest h2 version 1.4.200.

    I am getting the following error:

    org.h2.jdbc.JdbcSQLDataException: Cannot parse "TIMESTAMP" constant "aced0005740014323039392d30312d30315430383a30303a30305a"; SQL statement:

    With previous versions I used a custom column mapper to work around errors with H2.

      protected implicit val H2InstantMapper: BaseColumnType[Instant] = MappedColumnType.base[Instant, Timestamp](
        w => Timestamp.from(w),
        r => r.toInstant

    But this does not work anymore with the newest version.

    I also needed to use the PostgresProfile instead of the H2Profile because the BLOB data type was not working anymore.

    Can anyone help me with figuring out how to use Instant both with H2 (which I use in tests) and Postgres (which I use in prod)?
    I tried around for hours now and I am stuck..

    Matt Fulgo

    Hi folks,
    This has been covered a good bit in StackOverflow questions & in other places, but I have yet to find a solution that I'm happy with... I want to create an UPDATE statement with a variable number of columns. Something like

    coffees.filter(_.id === id)
      .map(t => change.cols(t))  // cols(t) returns Seq[Rep[_]]
      .update(change.values)  // values returns a Seq[_]

    I feel like there could be a way to do this with a custom Shape (like TupleShape but for Seq), but I was hoping for some more experienced folks to tell me if this is a futile endeavor or if it's a viable approach.

    There's also this gist but I'd rather not have to create a custom driver or rely on regexes to manipulate the query.

    Richard Dallaway
    I think it'll be tricky to get far with Seq, as I'd imagine a lot of type information (for each column) will get lost away to Any. I'd be tempted to use something like slick.collection.heterogeneous.HList, and there would be some fun/challenging type-level methods to get the types to exactly line up for cols and values.
    There might be easier ways. Depending on what you're basing the change on.
    If your data is a case class, maybe you can merge the values and update the whole role. As inspiration: https://github.com/davegurnell/bulletin (i.e., drop the map and just do the update; probably not suitable if you're shiping large amounds of data in a row)
    Matt Fulgo

    Thanks, Richard. In this case, I'm okay with missing out on some type safety. For the moment, I've ended up with something along these lines:

          Seq(s"UPDATE $tableName SET ",
            cols.map(_.getDumpInfo.mainInfo + " = ?").mkString(", "),
            " WHERE ID = ?",
            " LIMIT 1",
          (_: Unit, pp: PositionedParameters) => {
            (values :+ id).foreach {
              case v: Boolean => pp.setBoolean(v)
              case v: Byte => pp.setByte(v)
              case v: Date => pp.setDate(v)
              case v: Double => pp.setDouble(v)
              case v: Float => pp.setFloat(v)
              case v: Int => pp.setInt(v)
              case v: Long => pp.setLong(v)
              case v: Short => pp.setShort(v)
              case v: String => pp.setString(v)
              case v: Time => pp.setTime(v)
              case v: Timestamp => pp.setTimestamp(v)
              case v => throw new SQLException("update doesn't know how to handle parameter (" + v + ")")

    It's not quite complete because it doesn't handle NULLs, but it works for my current needs.

    Martijn Blankestijn
    Hi, been searching everywhere, but was not able to find how to do the following:

    Given the following for PostgreSQL

    select *from X x where (x.id, x.name) in ( (1,'foo'), (2,'bar'))

    how do I do this with Slick 3.3.3? The compiler never seems to agree with me

    Richard Dallaway
    Ah yes... inSet doesn't seem to support tuples. We might be able to teach Slick how to do that, but the workaround would be to transform into a (id ===1 && name == "foo") or (id === 2 && name === "bar"). Sounds horrible, but the code isn't too much. Old example: https://github.com/d6y/list-of-tuples/blob/eaa2903332d7797ac38d8807fa598fd2a5aad344/src/main/scala/or-example.scala#L52-L55
    Martijn Blankestijn
    Will give it a try, thanks @d6y !
    Hi, I want to connect from slick to mssql when select to the table contain column type NVarchar don't return the result for me. because slick don't add character N ( Unicode NVARCHAR Strings) . how can cusotme fucntion add N character.
    ex) select * from customer where title like N'%tt%'
    how can I enable the unicode prefix in slick?
    plz help me
    Felipe Bonezi
    Hey guys, is there anyone working on MongoDB support for Slick?
    Richard Dallaway
    @felipebonezi Not that I know of. There was some investigation some years back (there are still open tickets mentioning MongoDB).
    Felipe Bonezi
    @d6y Do you know any way to study more about Slick implementations and your archicture?
    I'm intended to try implement MongoProfile or to improve my skills hehehe.
    Richard Dallaway
    Jump over to https://scala-slick.org/docs/, and in the Talks section there are a couple there from Stefan. The Compiling Collections to SQL talk gives you insight into the query compiler (the steps Slick implements to go from a collection to SQL). Maybe start with the talk before that about Lifted embedding.
    Felipe Bonezi
    Thanks @d6y
    I've already downloaded the Essential Slick Book
    Georgios Larkou
    Hello guys one question, we observed that .filterNot(_.name === "test") does not include the null values as intended. Is there a better way to construct my queries instead of filter(x=> x.name.isEmpty || x.name =!= "test")
    Artsiom Miklushou
    How can I do constant query similar to SELECT 1 (Query(1)), but I need List(1) for example?
    Richard Dallaway
    Hi @mikla - you can use .to[T[_]], for example: Query(1).to[List]
    Artsiom Miklushou
    @d6y thx, interesting!
    What i'm trying to achieve is: mix some constant values to left join.
    Something similar to:
                          (CAST('316df2ac-14d0-468e-8e2e-0e5a54a8abca' as uuid)),
                          (CAST('47700d3b-b1fc-402f-80e5-a113ae792aca' as uuid)),
                          (CAST('965c0657-0bdd-4842-a127-9547b9c58ca3' as uuid))
                          ) AS q (col1)
    left join table on col1 = employee_id;
    Guillaume Noireaux
    Hello people, is it possible to read a bigint column as a String? Rather than as a Long? Thanks!
    Richard Dallaway
    @gnoireaux I believe you can do a table.map(row => row.myBigIntCol.asInstanceOf[String]) but not 100% sure. I'd expect that would CAST as the SQL level. Let us know how you get on.
    1 reply
    Richard Dallaway
    @mikla ooh. That's kind of odd looking, but I think you want to have a fixed query of uuids so you can go:
    ids.join(table).on(_ === _.employee_id)
    The type id ids would need to be a Query[Rep[X]], X, Seq] where X is whatever the type is for the uuid. I
    If, for the sake of argument, we were looking at Longs I think ids could be:
      val ids: Query[Rep[Long], Long, Seq] = Query(1L) ++ Query(3L) ++ Query(5L)
    Maybe there's something in that you can try. (I've never had to use Query.apply directly like that for a real application)
    Artsiom Miklushou
    @d6y Thank you very much!
    Anirudh Vyas

    I am trying to run this query:

    sql"""select  distinct r_.server_request_id, r_.raw_request from  #$tableName r_  where  r_.server_request_id in ( #$sids ) and r_.created < #$downTime  and r_.created > #$tillTime""".as[(String, String)]

    when I look at raw sql

    s""" select  distinct r_.server_request_id, r_.raw_request from  #$tableName r_  where  r_.server_request_id in (#$sids) and r_.created < #$downTime  and r_.created > #$tillTime""".stripMargin

    And paste it to run on postgres with values it prints - I get correct result, however with above sql""" syntax I get empty result -- any suggestions for me would be great

    I tried writing non sql way too:

    table.map(server_request_id, raw_request, created_date).filter(dates).filter(_.server_request_id inSet serverRequestIdList).map(server_request_id, created_date).result

    but seems to give me same empty vector as result...

    Anirudh Vyas
    the map, filter seems to work. still would be curious to know whats wrong with above sql