Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    nafg
    @nafg
    @rleibman no, follow slick/slick#2187
    Or get involved with it
    Meanwhile you can of course have some modules on 2.13 and some on 3 in your application
    James Phillips
    @jdrphillips
    @MichalPawlicki I'll give it a look - thanks
    nafg
    @nafg
    If anyone wants to video chat about Slick, or possibly watch me do some slick-related coding, I'm on https://meet.google.com/umj-wvqv-xxs now
    Matt Oliver
    @halfmatthalfcat
    Hey everybody, question about migrations. So what is the best practice around changing column types which map to case class types and rolling those back?
    I'm basically looking for a way to fallback to the previous type in some ergonomic way without having to either (1) duplicate a lot of code or (2) somehow leverage the current model implicitly through the app depending on what "version" of the model is currently applied
    Matt Oliver
    @halfmatthalfcat

    For example I have a Table and associated mapped class

    case class MyModel(
      myPk: Int,
      someText: String
    )
    
    class MyTable(tag: Tag) extends Table[MyModel](tag, "my_table") {
      def myPk: Rep[Int] = column("my_pk")
      def someText: Rep[String] = column("some_text")
    
      def * = (myPk, someText) <> ((MyModel.apply _).tupled, MyModel.unapply)
    
      def pk = primaryKey("my_pk_pk", myPk)
    }

    I have a migration that changes the myPk column from an integer to a varchar, so I now need to somehow represent that change within my table and case class with the option to roll back. The actual DB rollback is handled (rolled my own migration framework based off of Forklift) but it's handling the code rollback that is alluding me.

    I could duplicate MyTable with myPk as an integer and then also duplicate MyModel using myPk as an int still but then I'm having to potentially weave these two competing tables and models through the code depending on whether we've migrated or rolled back...

    I almost need someway to version MyModel with myPk as a String as well as MyTable with myPk as a String/varchar
    Matt Oliver
    @halfmatthalfcat
    Something like https://github.com/alexarchambault/data-class 's @since might work if anybody has experience implementing that with Slick
    nafg
    @nafg
    Anyone want to watch me do some maintenance of Slick?
    Rohan Sircar
    @rohan-sircar
    @nafg I'd watch, but do you post on youtube? I'm asleep at that time.
    nafg
    @nafg
    @rohan-sircar I'm not looking to entertain, ;) I'm looking to be more motivated and one thing that helps is if I have someone to discuss what I'm doing with. So I'm thinking more of a small zoom or google meet call than broadcast on twitch / upload for posterity
    If you're interested let me know what time(s) are good for you
    Antoine Doeraene
    @sherpal
    I'd be interested yes. What is your time zone? 🙂
    Rohan Sircar
    @rohan-sircar
    @nafg oh ok. I'm interested too..
    Dheeraj Karande 🇮🇳
    @dheerajkarande_twitter
    @nafg me too! :)
    nafg
    @nafg
    @sherpal @rohan-sircar @dheerajkarande_twitter when is the next time you would be interested?
    1 reply
    nafg
    @nafg
    I'm in EST but not on a typical workday schedule
    Andy Czerwonka
    @andyczerwonka

    I have a use case where I have an optional column, and I want to write a filter that checks for a value when it's present or check for null it it's null.
    I initially wrote:

    table.filter(_.name === name)

    In this case, when None, the query generates name = null, which is not correct, I was expecting name is null, so I had to change my filter to:

    table
      .filterOpt(name) { case (t, n) => t.name === n }
      .filterIf(name.isEmpty)(_.name.isEmpty)

    That produces the right query, but it seems like I should get that behaviour for free when using an optional column. Those two filter are mutually exclusive.
    Is there a primitive I should be using instead?

    Antoine Doeraene
    @sherpal
    I think what you want is
    table.filter(elem => elem.name.isEmpty || elem.name === name)
    Andy Czerwonka
    @andyczerwonka
    No, that's not the same, because there is no check if name is empty
    Antoine Doeraene
    @sherpal

    Ah sorry I did not understand properly. Would it be

    table.filter(name match {
      case None => _.name.isEmpty
      case Some(actualName) => _.name === actualName
    })

    ? I'm unsure whether Scala will correctly infer the type of that filtering function, so you might have to help it a bit.

    nafg
    @nafg
    @sherpal @rohan-sircar @dheerajkarande_twitter I can start in a few minutes
    Rohan Sircar
    @rohan-sircar
    @nafg cool, I am up
    Although not for very long, it's late here
    nafg
    @nafg
    Ok, google meet good?
    Rohan Sircar
    @rohan-sircar
    sure
    @rohan-sircar you joining?
    @sherpal ?
    1 reply
    Andy Czerwonka
    @andyczerwonka
    @sherpal yeah, that was my first attempt, but the typechecker get's in the way, but I'm sure I could coerce it
    Dheeraj Karande 🇮🇳
    @dheerajkarande_twitter
    @nafg i totally missed your msg. Uhh!
    I would really like to join in, can we schedule it in advance next time. Please.
    nafg
    @nafg
    Sorry I don't know my schedule in advance, but hopefully Sunday
    nafg
    @nafg
    @sherpal @rohan-sircar @dheerajkarande_twitter anyone interested soon?
    1 reply
    Rohan Sircar
    @rohan-sircar
    Kinda tired, I probably wouldn't be able to do much other than just watch quietly. I could join if I'm not gonna be the only one.
    Could you maybe also post in the main gitter channel/ typelevel discord channel?
    naftoligug
    @naftoligug:matrix.org
    [m]
    I usually do slick stuff on sundays
    in any case not much I can do until that is approved. So if anyone can review please do so ;)
    Well, I suppose I could just work on a branch off of that branch.
    Ok so ping me when you're on and I'll see if I can do some more stuff then
    Antoine Doeraene
    @sherpal
    I'm there if you'd like to give it a go, otherwise I can do on Sunday :) (Yesterday it was Belgium-Croatia so I had to watch :p )
    nafg
    @naftoligug:matrix.org
    [m]
    can't now. Until what time?
    Antoine Doeraene
    @sherpal
    now it's 9pm for me, until 11pm.
    but otherwise on Sunday it's good for me :)
    Naveen
    @dexter2305

    Model class & Table class are respectively. I am not able to understand compilation failure with insert Query. Can someone help ?

    case class Task(id: Int = -1, text: String, project: Option[String], context: Option[String], completed: Boolean)
    class Tasks(tag: Tag) extends Table[Task](tag, "tasks"){
      def id: Rep[Int] = column[Int]("id")
      def text: Rep[String] = column[String]("text")
      def project: Rep[Option[String]]= column[Option[String]]("project")
      def context: Rep[Option[String]] = column[Option[String]]("context")
      def isCompleted: Rep[Boolean] = column[Boolean]("isCompleted")
      override def * = (id, text, project, context, isCompleted) <> ( Task.tupled, Task.unapply)
    }

    InsertQuery looks like this now.

    val insertQuery= tasks += newTask

    A lot of examples are in similar way but I could not figure out the difference here for a couple of hours now.

    Naveen
    @dexter2305
    Found: I missed import slick.jdbc.PostgresProfile.api._. Is there a way to simplify the inclusion ? class Tasks should have this and also the class that has the insertQuery. That factor is forcing to make Tasks & Repositoy to be in the same file.
    nafg
    @nafg
    Nah you just need that import in every file you do query stuff
    Scala 3 export might be able to solve that, not sure