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
    No, but does it resemble one of the postgres json operators?
    Also how is it defined
    Matthew Daumen
    @mdaumen
    Hey there is a @> operator in the tminglei/slick-pg source
    The definition is as follows:
    `def @>[P2,R](c2: Rep[P2])(implicit om: o#arg[JSONType, P2]#to[Boolean, R]) = {
        om.column(jsonLib.Contains, n, c2.toNode)
      }`
    I have this line in a query: .filter({ case (_, pr) => pr.predicate @> Json.parse(s"""{"userRole":["$userRole"]}""")})
    Seems like I'm moving in the right direction.
    Matthew Daumen
    @mdaumen
    My driver is configured with Play! Json so I think that is the right way to pass that arg. Not 100% though.
    Matthew Daumen
    @mdaumen
    In case it ends up mattering - the above worked!
    Jens Grassel
    @jan0sch

    Hi,
    I was wondering if something like this is possible using json helpers:

    dbConfig.db.run(myTable.filter(_.state.~>("finished") === true).result.headOption)

    Where state is a JSON field on the table having a finished attribute which is boolean.

    However the compiler is complaining:

    [error] ... Cannot perform option-mapped operation
    [error]       with type: (io.circe.Json, Boolean) => R
    [error]   for base type: (io.circe.Json, io.circe.Json) => Boolean
    [error]     dbConfig.db.run(myTable.filter(_.state.+>("finished") === true).result.headOption)
    [error]                                                           ^
    [error] ... ambiguous implicit values:
    [error]  both value BooleanCanBeQueryCondition in object CanBeQueryCondition of type => slick.lifted.CanBeQueryCondition[Boolean]
    [error]  and value BooleanColumnCanBeQueryCondition in object CanBeQueryCondition of type => slick.lifted.CanBeQueryCondition[slick.lifted.Rep[Boolean]]
    [error]  match expected type slick.lifted.CanBeQueryCondition[Nothing]
    [error]     dbConfig.db.run(myTable.filter(_.state.+>("finished") === true).result.headOption)
    [error]                             ^
    Any ideas which can guide me in the right direction?
    Gavin Bisesi
    @Daenyth
    maybe try ("finished").asColumnOf[Boolean]?
    Jens Grassel
    @jan0sch
    @Daenyth Awesome, thank you. It compiles fine, now it only has to work. ;-)
    Jens Grassel
    @jan0sch
    Ok, it fails at runtime with "could not convert type jsonb to boolean". :-|
    Jens Grassel
    @jan0sch
    I use +>> now and compare to the string value. Not the best thing but it works.
    Vladimir
    @invis87
    Hi guys, can you give me a hint - how to save Timestamp in UTC?
    I am using java.time.Instant and this converter:
    implicit private val instantColumn: JdbcType[java.time.Instant] = MappedColumnType.base[java.time.Instant, java.sql.Timestamp](
        instant => java.sql.Timestamp.from(instant),
        column => column.toInstant)
    but when I save date to Database it it saved with my local offset :(
    Gavin Bisesi
    @Daenyth
    Make sure your server, db server, and db connection are all set to utc
    Rakesh
    @rakeshkr00
    I have used codegen with slick pg. The generated code throws could not find implicit value for parameter tt: slick.ast.TypedType[Option[com.vividsolutions.jts.geom.Geometry]] . I have defined my postgres profile as given at https://github.com/tminglei/slick-pg. Am I missing something here?
    If I raplace com.vividsolutions.jts.geom.Geometry with String, the error goes away.
    Gavin Bisesi
    @Daenyth
    you need to tell slick how Geometry maps to a database type it knows about
    Rakesh
    @rakeshkr00
    I thought slick pg would help taking care of it. BTW, how to let slick know that required mapping?
    Gavin Bisesi
    @Daenyth
    hmm it actually looks like it should
    does your slick profile extend PostGISSupport?
    Rakesh
    @rakeshkr00
    Yes, I have created my profile using the suggestion given at https://github.com/tminglei/slick-pg
    Rakesh
    @rakeshkr00

    I have used codegen with slick pg. The generated code throws could not find implicit value for parameter tt: slick.ast.TypedType[Option[com.vividsolutions.jts.geom.Geometry]] . I have defined my postgres profile as given at https://github.com/tminglei/slick-pg. Am I missing something here?

    Any suggestion on that?

    Rakesh
    @rakeshkr00
    The issue got resolved after I mixin with PostGISImplicits in the MyAPI object definitaion in the driver profile.
    nafg
    @nafg
    I'm trying to figure out how to use stringAgg. Here is the query I'm trying to convert:
    select last_name,
           first_name,
           (select string_agg(medical_specialty.name, '; ') from medical_specialty join doctor_medical_specialty dms on medical_specialty.id = dms.medical_specialty where dms.doctor = doctor.id)                                                   as specialties,
           (select string_agg(medical_subspecialty.name, '; ') from medical_subspecialty join doctor_medical_subspecialty dms on medical_subspecialty.id = dms.medical_subspecialty where dms.doctor = doctor.id)                                                   as subspecialties,
           cell_number,
           email_address,
           rating,
           (select string_agg(hospital.name, '; ') from hospital join doctor_hospital dh on hospital.id = dh.hospital where dh.doctor = doctor.id)                                                    as hospitals,
           (select string_agg(o.name, '; ') from doctoroffice o where o.doctor = doctor.id) as offices
    from doctor
    I'm trying this:
          Doctors
          .map { doc =>
            val specialties =
              ManageDoctorsDbActions.specialtiesQuery.filter(_._1 === doc.lookup).map(t => stringAgg(t._2.name, "; "))
            (doc, specialties)
          }
    and it fails pretty badly, and seems wrong. This is somewhat better?
          Doctors
            .map { doc =>
              val specialties =
                stringAgg(ManageDoctorsDbActions.specialtiesQuery.filter(_._1 === doc.lookup).map(t => t._2.name), "; ")
              (doc, specialties)
            }
    I get this:
    This message was deleted
    nafg
    @nafg
    image.png
    nafg
    @nafg
    It seems like stringAgg is essentially Rep[A] => Rep[String]
    nafg
    @nafg
    I gave up on using the slick-pg implementation. I wrote this instead and it compiles:
        import FunctionSymbolExtensionMethods._
    
    
        val StringAgg = new Library.SqlAggregateFunction("string_agg")
        def stringAgg(q: Query[Rep[String], _, Seq], delimiter: String)
                     (implicit tm: TypedType[Option[String]]): Rep[Option[String]] =
          StringAgg.column[Option[String]](q.toNode, LiteralNode(delimiter))
    
    ...
    
          Doctors
            .map { doc =>
              val specialties =
                stringAgg(ManageDoctorsDbActions.specialtiesQuery.filter(_._1 === doc.lookup).map(_._2.name), ", ")
              (doc, specialties)
            }
    @tminglei
    I based it off how slick's built in aggregate functions are defined
    nafg
    @nafg
    ...except it's generating the wrong SQL now
    nafg
    @nafg
    Gave up and went with plain sql query :(
    Gavin Bisesi
    @Daenyth
    I think there's issues with stringAgg.. check the bug tracker
    nafg
    @nafg
    @Daenyth don't see any bugs about it
    Gavin Bisesi
    @Daenyth
    not sure, I recall someone on our team hit weird issues with it but I don't remember what
    Naveen Kumar Parachur Cotha
    @naveencotha-zt
    Hi, is there a getting started guide or something to read up?
    Gavin Bisesi
    @Daenyth
    Essential Slick is what I recommend