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
    @ClintCombs also, I would have more time if someone wants to pair program with me (or just act as a sounding board)
    Alex Leeds
    @leedsalex

    Hi, I have a question around compiled queries, in regards to inserts / upserts.
    Is there a difference between these two statements?

    Assuming val ts = TableQuery[T]:

    • Compiled(ts) += row
    • ts += row
    Priyanka Gugale
    @ggl_priyanka_twitter

    I am getting error Type CustomerRow does not conform to upper bound Product with Serializable of type parameter R
    This is with generated classes using slick-codegen utility. I have more than 22 fields in my table.

    Scala version: 2.13
    Slick version: 3.3.3

    1 reply
    j.kugiya
    @j.kugiya:matrix.org
    [m]
    @nafg: There are several issues that have stopped progressing, which ones do we need to resolve for the next release?
    nafg
    @naftoligug:matrix.org
    [m]
    j.kugiya: none are blocking a release. I just have to have time to switch over to sbt-ci-release IIRC (or something like that), as Seth requested. I haven't had a really free Sunday in a while so I haven't gotten to it yet. But if someone wants to pair program with me, or just be a sounding board while I work on it, I will find time a lot more easily. (When there are too many other things in front of me I can't concentrate otherwise.)
    Sunil Kumar Yadav
    @aiodsunil
    Hi All I am facing one issue while doing group by on some id and trying to get value of Cost case class which have filed amount to sum it => case class Booking(id,Cost) case class Cost(amount:Double) getting issue can’t covert Rep[Cost] to Cost ..any idea how to solve it ..groupBy with aggregation method on case class field
    1 reply
    val action = bookings.groupBy { booking =>
    booking.id
    }.map {
    case (id, group) =>
    (id, group.size, group.map { obj =>
    obj.cost.amount
    }.sum)
    }
    Gajendra Naidu Thalapaneni
    @GajendraNaidu
    Need help, I have a list of database operations as Futures, when I run them sequentially, the DB update is not updated in the same sequence. Using AsyncExecutor, with Slick "3.3.3" and Postgresql
    Antoine Doeraene
    @sherpal
    Could you post the code?
    Gajendra Naidu Thalapaneni
    @GajendraNaidu
    @sherpal Below code doing sequentialize futures.
    def sequentializeFutures[A, B](l: Iterable[A])(fn: A => Future[B])(implicit ec: ExecutionContext): Future[List[B]] =
        l.foldLeft(Future(List.empty[B])) { (previousFuture, next) =>
          for {
            previousResults <- previousFuture
            next <- fn(next)
          } yield previousResults :+ next
        }
    And those futures includes database operations, like create row and delete row.
    Antoine Doeraene
    @sherpal
    That is indeed weird. the only thing I see is if you where to give as l an Iterable[Future[A]] and for fn the identity function.
    phlamenco
    @phlamenco
    Need help, is TableQeury thread safe in play framework?
    can I just use one TableQuery object all through my play application?
    Antoine Doeraene
    @sherpal
    Yes, it's an immutable object. Actually, everything in Slick is immutable, until the point where you execute db.run.

    In particular, you can do things like this

    val myTable = TableQuery[Stuff]
    val onlyActiveStuff = myTable.filter(_.active)

    and use onlyActiveStuff throughout your application freely.

    phlamenco
    @phlamenco
    Got it, thanks
    Oscar Vargas
    @ovargas_natera:matrix.org
    [m]

    Hello! I am having some compile errors while trying to make a join where keys are of different type (String Vs Long).

    .join(CNCReportShipmentRecord.table).on { case (((cf, pk), cc), cnc) =>
        cc.cncreportshipmentrecords_id === cnc.id
    }

    Here I am comparing Rep[String] with Rep[Long] and therefore I am having the following compile time error:

    Cannot perform option-mapped operation
          with type: (String, Long) => R
      for base type: (String, String) => Boolean
              cc.cncreportshipmentrecords_id === cnc.id

    How could I "map" the Rep[String] to a Rep[Long] ?

    Oscar Vargas
    @ovargas_natera:matrix.org
    [m]
    This worked for me: cc.cncreportshipmentrecords_id === cnc.id.asColumnOf[String]
    水山清风
    @djx314
    @ovargas_natera:matrix.org If compare with String and Long in database is no problem, that's ok.
    kyle tilman
    @ktilcu
    Hey Friends! I'm newish to scala and slick. I was wondering if there was any way to override the update method provided by a DBIOAction. I was hoping to add some tracking to track all changes to this model.
    nafg
    @naftoligug:matrix.org
    [m]
    Wdym tracking
    kyle tilman
    @ktilcu
    for me it's instrumentation to start the transition to emitting events for a model being updated. Unfortunately the code is structured in a way where we do these updates in a ton of places.
    @naftoligug:matrix.org Forgot to tag in the previous message
    nafg
    @naftoligug:matrix.org
    [m]
    @ktilcu: I think you will have to refactor your code
    Andy Czerwonka
    @andyczerwonka
    Wondering if anyone has an example of how to inject ExecutionContext into a Scala-based migration. I can't inject it at the class level, because the Flyway migration won't find it.
    Andy Czerwonka
    @andyczerwonka
    Other than the global of course
    Artie Pesh-Imam
    @apeshimam

    Hi Im trying to use testcontainers to run a postgres container to test my DAO and the future is just never fulfilling:

      /**
       * Before any specs are run, create the container and run the migrations
       */
      override def beforeAll(): Unit = {
        super.beforeAll()
        container.start()
    
        val configuration = new ClassicConfiguration()
    
        configuration.setDataSource(
          container.container.getJdbcUrl,
          container.container.getUsername,
          container.container.getPassword)
        configuration.setLocations(new Location("classpath:db/migration"))
    
        val flyway = new Flyway(configuration)
        val result = flyway.migrate()
        out.println(f"successfully ran migrations: ${result.migrationsExecuted}")
    
        import com.zaxxer.hikari.HikariDataSource
        val ds = new HikariDataSource
        ds.setJdbcUrl(container.container.getJdbcUrl)
        ds.setUsername(container.container.getUsername)
        ds.setPassword(container.container.getPassword)
        ds.setLogWriter(new PrintWriter(System.out))
        db = Database.forDataSource(ds, None)
    
      }
    class GeneralLedgerDAOSpec extends AsyncBaseSpec with DatabaseSpec {
      val ledgerUuid = UUID.randomUUID()
      val companyUuid = UUID.randomUUID()
      val name = "Test Ledger"
      val ledger = Ledger(ledgerUuid = ledgerUuid.toString, companyUuid = companyUuid.toString, name = name)
    
      "GeneralLedgerDAO" should {
        "insert a general_ledger" in {
    
          val generalLedger =
            GeneralLedger(generalLedgerId = ledgerUuid, companyId = companyUuid, None, json = ledger.asJson)
    
          val dao = new GeneralLedgerDAOImpl(db)
          val result = dao.createGeneralLedger(generalLedger)
          result.futureValue shouldBe ()
        }
      }
    }

    I can provide more of the code but it isnt that interest. It look like the connection pool is being created fine. And it looks like everything should be good, but my spec just never gets a value out of the future.

    any suggestions?
    Yuliban
    @yupegom_gitlab
    Hello everyone. So this might be a dumb question but just wondering if there are any benefits of using the ? operator vs declaring the field as optional when defining the table. Is it just a "nicer" way to do it?
    nafg
    @naftoligug:matrix.org
    [m]
    @yupegom_gitlab: you should give the column an Option type. Only use .? when for some reason you have no other choice, IMO
    Aditya Maheshwari
    @adityamundra
    Is there any performance gain if we run multiple DBIO vs a single Seq of DBIO(by using DBIO.sequence)?
    Devidatta Mohapatra
    @ddm12345
    I am using insertOrUpdate in slick with returning . But in case of both insert or update the query seems to be returning Some(_). Can anyone please help. Here is the snippet.
    val insertQuery = (notifications returning notifications.map(_.json)).insertOrUpdate(notification)
    dbConfig.db.run(insertQuery).map {
      case Some(_) => NotificationDatabaseAction.Insert
      case None    => NotificationDatabaseAction.Update
    }
    phlamenco
    @phlamenco
    Need help. When update a row, I usaually use tableQuery.filter().update(caseClass), but some fields can't be updated, so I use tableQuery.filter().map().update(), the problem is the case class has too many fields, the number of unupdated field may be 2 or 3, it's very tedious to use mapping to do updating
    1 reply
    nafg
    @nafg
    @adityamundra I can't say for sure but I doubt it. Also see DBIO.seq
    sebarys
    @sebarys
    Hi
    I've asked one question here https://github.com/slick/slick/discussions/2314
    Is it preferred way to ask questions about Slick functionalities?
    nafg
    @nafg
    @sebarys that's fine but there aren't a lot of people that can help. That said, it would help if you made your question clearer
    sebarys
    @sebarys
    @nafg thanks for answer :) I've added more context there
    laubus96
    @laubus96
    Hello, do you know if with slick you can ingest data to timescaledb, more specifict, into hypertable
    N.S. Cutler
    @godenji

    Not sure if anyone can help here, but custom Slick codegen is truly an adventure in multi-threaded non-deterministic nonsense :)

    In the early days I had a Slick 2.x code generator that worked well enough despite the tangled web that is the cake pattern. Yesterday I updated everything to Slick 3.3.3, Hikari 3.4.5, etc. and after some hoop jumping with missing logging, managed to get the generator running with plenty of debug output. Everything works...until it doesn't. For each run I get different manner of NoClassDefFoundError, either in my custom generator code, or in Slick's -- of course my own code is obviously on the classpath, as is all of the libraryDependencies code (copied in sbt Def.task block).

    Only thing I can think of is that Slick's wondrous non-blocking (but really blocking) DBIO is dead locking at some point and breaking the generator run. Anyone have experience with custom Slick codegen?

    Would be truly amazing to run the code generator in a blocking fashion since, you know, for local dev environment, who cares, the whole run will complete in a couple of seconds max.

    Anyway, when it worked it was quite useful...

    N.S. Cutler
    @godenji
    Managed to resurrect codegen with latest dependencies, not without hassle, but these libraries are hard to come by in the Scala ecosystem, and Slick codegen can be used for many things, not just Slick model mappings...
    nafg
    @nafg
    @godenji try my code generator
    It's one of the modules in https://github.com/nafg/slick-additions
    It uses scalameta instead of strings, for one thing
    That said, your issue seems strange, not what the cause is
    Maybe sometime I could help you on a call
    N.S. Cutler
    @godenji
    Looks good, my code gen needs are more complex though, so full blown custom code generator was required when I put it together several years ago (db model, mapping, play forms, api routes, stub controllers, etc.). Anyway, as I said, Slick codegen is probably the best tool for this scenario in the scala ecocsystem; it's just heavy use of cake pattern and non-blocking IO make this task harder than it needs to be.
    nafg
    @naftoligug:matrix.org
    [m]
    @godenji: I think mine lends itself well to arbitrary tasks
    N.S. Cutler
    @godenji
    I'll check it out, there's another one I saw as well that takes a SourceCodeGenerator as sbt task key. Regardless, I have to ouput multiple source files per entity (e.g. User entity has separate files generated for model, mapper, api route, and controller stub). Because of this I just run everything through my custom generator since Slick codegen default isn't setup for this kind of thing at all.