Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Rob Norris
    @tpolecat
    Right right.
    Glen Marchesani
    @fizzy33
    fwiw here is a real world example of the DSL
    
      object DataFlow {
        lazy val mapper = m3.jdbc.managed_mapper.Mapper[DataFlow, String]
        class TableDsl(join: QueryDsl.Join = QueryDsl.RootJoin) {
          val uid = QueryDsl.field[String]("uid", join)
          val label = QueryDsl.field[String]("label", join)
          val ownerUid = QueryDsl.field[String]("ownerUid", join)
          val extraData = QueryDsl.field[Json]("extraData", join)
          val audit_version = QueryDsl.field[Long]("audit_version", join)
          val audit_userGroupUid = QueryDsl.field[String]("audit_userGroupUid", join)
        }
        val queryDsl = new QueryDsl[DataFlow, TableDsl](mapper, new TableDsl)
        def query(whereFn: TableDsl => QueryDsl.Condition): querydsl.SelectQuery[DataFlow, TableDsl] = queryDsl.query(whereFn)
        def update(set: TableDsl => Iterable[querydsl.UpdateQuery.Assignment[_]]): querydsl.UpdateQuery[TableDsl] = queryDsl.update(set)
      }
    
      @SqlName("DataFlow")
      @CompanionGen
      case class DataFlow(
        @PrimaryKey(seq=0) uid: String = Uid.random(),
        label: String,
        ownerUid: String,
        extraData: Json,
        @ReadOnly audit_version: Long,
        @ReadOnly audit_userGroupUid: Option[String] = None,
      ) extends DataMixins.DataFlowMixin
    
      object DataFlowRun {
        lazy val mapper = m3.jdbc.managed_mapper.Mapper[DataFlowRun, String]
        class TableDsl(join: QueryDsl.Join = QueryDsl.RootJoin) {
          val uid = QueryDsl.field[String]("uid", join)
          val startTime = QueryDsl.field[net.model3.chrono.DateTime]("startTime", join)
          val trace = QueryDsl.field[Boolean]("trace", join)
          val finishTime = QueryDsl.field[net.model3.chrono.DateTime]("finishTime", join)
          val stepUid = QueryDsl.field[String]("stepUid", join)
          val success = QueryDsl.field[Boolean]("success", join)
          val errorMessage = QueryDsl.field[String]("errorMessage", join)
          val state = QueryDsl.field[Json]("state", join)
          val extraData = QueryDsl.field[Json]("extraData", join)
          val dataFlowUid = QueryDsl.field[String]("dataFlowUid", join)
          lazy val dataFlow: DataFlow.TableDsl = {
            val childJoin = QueryDsl.createJoin(join, "dataFlow", DataFlowRun.queryDsl.tableDsl, ()=>dataFlow, DataFlow.mapper) { (from,to) =>
             from.dataFlowUid === to.uid
            }
            new DataFlow.TableDsl(childJoin)
          }
        }
        val queryDsl = new QueryDsl[DataFlowRun, TableDsl](mapper, new TableDsl)
        def query(whereFn: TableDsl => QueryDsl.Condition): querydsl.SelectQuery[DataFlowRun, TableDsl] = queryDsl.query(whereFn)
        def update(set: TableDsl => Iterable[querydsl.UpdateQuery.Assignment[_]]): querydsl.UpdateQuery[TableDsl] = queryDsl.update(set)
      }
    Rob Norris
    @tpolecat
    I see, ok.
    Glen Marchesani
    @fizzy33
    some extra cruft in there but the gist of it is there with a join exposed
    Rob Norris
    @tpolecat
    I would probably look at this as an add-on rather than a feature that ships with Skunk or doobie. But it should work with either if you can generate SQL and you know the types of parameters and result columns.
    Glen Marchesani
    @fizzy33
    so you could
    DataFlowRun.query(aa => aa.uid = "xyzpdq")
    exactly
    Rob Norris
    @tpolecat
    Have you looked at Quill?
    Glen Marchesani
    @fizzy33
    a long time ago
    I added it to my list of tasks for today to take another look at it
    I really love that I can make this all effects based with doobie
    and having been staring at doobie and skunk much of the painful internal code is gone
    and the diagnostics look really solid
    which is a big deal for us given the nature of the system we are working on...
    how they fail because they will fail has to be a big part of how we build
    oh
    a join would be
    Rob Norris
    @tpolecat
    Yeah diagnostics with doobie are awful. If it matters for you then definitely use Skunk.
    Skunk also does execution tracing and it's :fire:
    Glen Marchesani
    @fizzy33
    yeah we have two worlds one is the postgres side of things and the other is the legacy side (oracle and db2)
    oh nice
    so will end up using both doobie and skunk
    the join example is
    DataFlowRun.query(aa => aa.dataFlow.uid = "mydataflow")
    Rob Norris
    @tpolecat
    image.png
    trace example
    Glen Marchesani
    @fizzy33
    snap
    Rob Norris
    @tpolecat
    need to do some optimizing!
    In your join how do you lift that lambda into something that can become a join condition?
    Glen Marchesani
    @fizzy33
    oof
    Rob Norris
    @tpolecat
    I would expect aa.datafield.uid === "mydataflow" or something like that, with a custom operator
    Glen Marchesani
    @fizzy33
    my examples are wrong
    yeah === not =
    Rob Norris
    @tpolecat
    :+1:
    Glen Marchesani
    @fizzy33
    DataFlowRun.query(aa => aa.dataFlow.uid === "mydataflow")
    Rob Norris
    @tpolecat
    yep yep
    Slick does something similar.
    Glen Marchesani
    @fizzy33
    yeah it has been a while but I am sure I stole with pride from slick
    at the time slick didn't have it so we went it alone
    Rob Norris
    @tpolecat
    The lifted encoding is nice because it's all in userland. Quill uses a macro to rewrite the source, so the code you write looks like normal Scala operating on collections.
    Both solutions are complicated unfortunately.
    Glen Marchesani
    @fizzy33
    yeah
    for my team(s) I have found generated code much much much more managable
    than macros
    so we have gone that route
    plus issues with accessing the production database from dev, etc, etc
    and the prod database not matching the other db's enough to be reliable, etc, etc
    oh interesting I am just catching what you are saying about quill... So quill becacuse of it's macro you CAN write = instead of === oh that is a very nice use of macros :-D
    Rob Norris
    @tpolecat
    I avoid machinery as much as possible so it's not really my thing, but a lot of people are using it and really like it.
    Glen Marchesani
    @fizzy33
    :-)