Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    LarryFinn
    @LarryFinn
    Is there a way to use mysql index hints without "raw" sql?
    Carsten
    @carstenlenz

    Hi everyone.

    Maybe anyone can give me hint with this: I have a case class for a row (mapped in a Table class) very standard - now I want to use an instance of this case class as a constant query (select field1, field2) - I haven't found an elegant way to do so - I could create a tuple out of the case class and then do a Query(tupledcaseclass) - is this the only way to do so ?

    jdaniel-at-yottly-dot-com
    @jdaniel-at-yottly-dot-com
    hello, I have two tablest1 and t2 with rows of type (Int, A)and (Int, Option[B]) and I do something like t1.joinLeft(t2).on(_._1 == _._1) but that gives me Rep[Option[(Rep[Int], Rep[Option[B]])] on the right, what could I do to t2 to actually get only rows with (Int, B) apart from the ugly .filter(_._2.isDefined).map(_.map(_.get)) to get Rep[Option[(Rep[Int], Rep[B])]] instead, and then ultimately drop the key used for joining to arrive at Rep[Option[B]] on the right, so that in the end I have a query that yields rows of type ((Rep[Int], Rep[A]), Rep[Option[B])? Is some syntax eluding me? There has to be some kinf of flattening operation that does this, right?
    Gavin Bisesi
    @Daenyth
    @jdaniel-at-yottly-dot-com I think the ugly solution is the way; it models the shape of sql that you'd use.
    I mean you can also use sql"" but that has its own drawbacks
    Tim Moore
    @TimMoore
    RFC: slick/slick#2082 proposal to move the Slick website to scala-slick.org
    Sharon (Sean) Rolel
    @Mosho1
    I'm creating these fairly huge queries (hundreds of lines) and calling selectStatement takes more than half a second. is there a more performant way to get the string result of the query? I'm using slick 2, would 3 be more performant?
    Alexander Samsig
    @Asamsig
    My best advice, would be to see if you can use Compiled queries
    Sharon (Sean) Rolel
    @Mosho1
    hmm that's interesting. but what we're doing is creating queries on the fly, based on parameters. so I don't know what shape the query will have or what parameters it would take
    until runtime
    Gavin Bisesi
    @Daenyth
    You might consider making a View in the db if there's some common join operation or whatever that's annoying to express
    Sharon (Sean) Rolel
    @Mosho1
    yeah, we do use some views
    but these queries are very big and very dynamic
    Lanlan Pang
    @panglanlan
    Hi I am using slick and postgres to develop an application, and have issues like this: https://stackoverflow.com/questions/58532535/how-to-use-slick-with-postgres-table-that-has-array-column can someone help me to figure out what's wrong with the sample code I provided?
    Artem Egorkine
    @arteme
    I'm trying to chain validations. I have a bunch of functions that return Future[ValidatedNel[String,A]] that are dependent on results of previous validations. What is the most sensible way to work with them? If I nest Future for-comprehension and mapN validations, then the result is something like Future[ValidatedNel[String,FutureValidatedNel[String,Future[ValidatedNel[String,X]]]]]
    How can I flatten that?
    Artem Egorkine
    @arteme
    Ok, I can convert to EitherT and flatMap
    Mäx K.
    @maexrakete

    Hey guys! How can I return a default sorting of some kind when using sortBy? I have this code: https://gist.github.com/maexrakete/a99c6c5cc180bcde0423452045cb7282

    In line 9 i get a Rep[Double]. This is the distance of the search term to the column title. If there isn't a search term I just want to apply no ordering (or some default ordering) I thought of just returning a 0 if there's no search term so that the ordering is defaulted again, but I can't figure out how that's supposed to work

    Gavin Bisesi
    @Daenyth
    Move the sortBy call inside of the Option#map
    val filtered = filteredQuery(filter)
    filter
      .flatMap(_.term)
      .map(search => filtered.sortBy(a.title <<-> search))
      .getOrElse(filtered)
    actually
    I think there's a DSL op for that
    filterOpt
    Mäx K.
    @maexrakete
    I don't want to filter, i want to sort :D
    Gavin Bisesi
    @Daenyth
    oh no that's for filtering
    yeah
    then my sample
    FWIW filterOpt is implemented basically exactly as I suggest you do the sorting
    so it's definitely the way to go about it
    (getOrElse)
    Mäx K.
    @maexrakete
    that's it!
    so easy... I thought about way longer than I'd like to admit :D
    thanks!
    Guodong Qu
    @jasonqu
    Hey guys! how can I remove the quotes in the default generated sql from select `col` from `Test` where `id` = 3 to select col from Test where id = 3, thanks a lot!
    which is in MySQLProfile
    Ali Akhtar
    @AliAkhtar__twitter
    How do I use plain sql? When I try to do sqlu or sql in my code, I get a 'symbol not founderror. I'm importingimport slick.jdbc.PostgresProfile.api._`
    Clay Teeter
    @teeterc
    Hey all! Hopefully a quick question. Is there a way to profile the execution time of a DBIO?
    Clay Teeter
    @teeterc
    For anyone else. this is what i ended up doing.
    def timedDBIO[T, E <: Effect](message: String)(dbioAction: DBIOAction[T, NoStream, E])
                                   (implicit ec: ExecutionContext): DBIOAction[T, NoStream, E] = {
        val className = this.getClass.getCanonicalName
        val start = System.currentTimeMillis()
    
        for {
          r <- dbioAction
        } yield {
          println(s"${className}: ${message} took ${System.currentTimeMillis() - start} ms")
          r
        }
      }
    Gavin Bisesi
    @Daenyth
    @teeterc That's not a good general solution
    The start you have there is when the DBIO value is constructed, not when the query executes
    If you reuse the DBIO, you'll get times stacking up. Even if you don't, you'll be measuring "get db connection from the pool" as part of the execution time
    You need to use something like this
    val getTime: DBIO[Long] = DBIO.successful(()).flatMap(_ => DBIO.successful(System.currentTimeMillis))
    for {
      start <- getTime
      r <- dbioAction
      end <- getTime
      elapsed = end - start
    } yield ???
    have a look at slick-effect's DBIOAsync implementation for cats-effect, it has more structures and tests around it. Or if you're using cats-effect then you can do val getTime = Sync[DBIO].delay(System.currentTimeMillis) (the former is roughly the implementation)
    Drew Spencer
    @slugmandrew
    Hello all! New to Slick but enjoying learning it greatly
    However, my productivity has just been hampered as the documentation seems to have all vanished, along with all traces of slick from the lightbend website.... anyone know what's going on?
    Richard Dallaway
    @d6y
    The documentation is moving to a new domain. I think it will redirect in time, but for now you can go direct to: https://scala-slick.org/
    (here's the issue tracking this:slick/slick#2084 )
    Dmitriy
    @dpogretskiy
    heyo, did anyone try to hack some manual nextval into insertion query?
    something as simple as Rep.of[Long](sql"nextval('table_seq')") would be perfect, but obviously it's not that easy :)