Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    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
    but slick doesn't support scala 3 yet
    Antoine Doeraene
    @sherpal
    However you can still abstract away which profile you use (it can be helpful if you want to use the H2Profile in your tests (especially since compatibility between PostgresProfile and the postgres mode for h2 broke)
    nafg
    @naftoligug:matrix.org
    [m]
    In general that's not a good idea because of inherent differences between databases, especially nowadays that it's so easy to spin up a postgres instance with docker or via testcontainers.org
    Antoine Doeraene
    @sherpal
    Yes for advanced uses it's usually bad... But spinning a docker is still quite expensive
    nafg
    @naftoligug:matrix.org
    [m]
    It shouldn't be expensive
    Expensive how?
    Antoine Doeraene
    @sherpal
    I'm only speaking about computational power. You easily get 10-20s of overhead
    1 reply
    Naveen
    @dexter2305
    I am looking at "how to design the classes with domain object Task (as quoted in the snippet above) along with DAO/Repository. Now that we spoke of H2 (only for testing), question I am getting is - is it a good idea to test with H2 when the production is going to be something else. Kind of beginner with slick - not sure if this advisable. If so - any directions ? Thanks
    Antoine Doeraene
    @sherpal
    As nafg said above, it's easy (in terms of code) these days to spin up a database inside a Docker container with your database of choice (in this case, postgres). The only thing that you have to do is to apply the evolutions/migrations to it (because obviously, you get a fresh one) and put some data in it. How you apply these evolutions will depend on your evolutions framework (on the JVM in scala the two most probable are Flyway or Play, let us know if you need help ;) ). For managing the docker container, as suggested also, you can use https://github.com/testcontainers/testcontainers-scala
    Naveen
    @dexter2305
    Yes, I am spinning a docker container for postgres. Since it will be a fresh one, classSchemaGenerator is needed. SchemeGenerator requires Database and collection Table[Model]. There is also this sticky import statement import slick.jdbc.PostgresProfile.api._ which I want to keep it min files as possible. Given these I am looking for design these classes.
    Antoine Doeraene
    @sherpal

    The question is why you want to keep that import statement in as min files as possible? If it's because your project is the barebones for building other projects, then you can always store somewhere in a global object the profile you want to use. Something like

    object DatabaseGlobals {
      def profile = slick.jdbc.PostgresProfile
    }

    and then you can import that instead, via my.package.DatabaseGlobals.profile.api._.
    If the reason is for mocks in tests, then I think you can put your table definitions inside a trait which requires an abstract jdbc profile, and feed that profile by extending the trait (I think that works)