Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Gregg Hernandez
    @gregghz
    Also, fwiw, I think it was a mistake to make a uuid column parser since now it's super overloaded and has pretty weird semantics that only partially even map to what lucid does with it. I believe we only ever read a UUID from a byte array or blob column type. We should have just used a col parser for that type and then transformed to UUID in code. It would have made support the postgres UUID column easier
    Mark de Jong
    @Fristi
    The type of the column (created_at) is date time. You can write expressions in WHERE clauses like I did: AGE(now(), created_at) <= interval '5 minutes'
    Quill/Slick uses typeclasses to do different type conversions
    Might be interesting for you as well
    Mark de Jong
    @Fristi
    datetime = timestamp
    Gregg Hernandez
    @gregghz
    Typeclasses would be perfect except the only way I've found to use them in a string context like sql is via shapeless. It had a pretty significant negative performance impact.
    Gregg Hernandez
    @gregghz
    @Fristi thanks for that info. I believe the problem could be solved by creating an implicit PGInterval => Parameter and then instead of trying to interpolate a Long, with sql"... AGE(now(), created_at) <= interval '$long milliseonds' you could just interpolate the full PGInterval: sql"... AGE(now(), created_at) <= $pgInterval" (you might need the interval function too, I'm not sure). I haven't had a chance to test this. I will as soon as I can but feel free to give it a shot in the meantime.
    Gregg Hernandez
    @gregghz
      implicit class PGIntervalParameter(value: PGInterval) extends SingleParameter {
        protected def set(stmt: PreparedStatement, i: Int) = stmt.setObject(i, value)
      }
    And then you can query like this:
    val interval = new PGInterval(s"${sessionDuration.toMillis} milliseconds")
    sql"SELECT session_id, user_uuid, device_uuid FROM sessions WHERE session_id = $sessionId AND AGE(now(), created_at) < $interval"
    Gregg Hernandez
    @gregghz
    lucidsoftware/relate#48
    Mark de Jong
    @Fristi
    Thanks for your answer @gregghz.
    I'll try soon
    And report back :-)
    Mark de Jong
    @Fristi
    That works, I've reported it as well in the issue
    Thanks for your support @gregghz
    Gregg Hernandez
    @gregghz
    👍
    winry
    @fwrq41251
    Any one know how to split a sql into many lines?
    Use "+" to concat strings bring compile error
    Mark Siebert
    @msiebert
    http://lucidsoftware.github.io/relate/docs/writing-queries.html#query-composition suggests that using + with two sql"" strings should work. Is that not working for you?
    also that header on the documentation is all messed up @gregghz
    you should fix it with your mad css skillz
    James Judd
    @jjudd
    I'm pretty sure that sql"""<stuff>""" should also work, so you can just use a multiline string.
    winry
    @fwrq41251
    @jjudd works 👍
    Mark Siebert
    @msiebert
    oh yeah, I totally misunderstood your question. Sorry about that
    Drew O'Kane
    @drewokane
    hi, I'm having a bit of trouble with dates in a query. I'm attempting to do something like:
    val dateFormat = "YYYY-MM-DD HH:mm:ss"
    val start = new DateTime(2016, 1, 1, 0, 1, 1).toString(dateFormat)
    sql"select * from measurement where end_interval >= $start limit 10"
    Gregg Hernandez
    @gregghz
    is that a joda date time?
    Drew O'Kane
    @drewokane
    yes it is
    Gregg Hernandez
    @gregghz
    there's no interpolator for that
    you also don't want to do toString on it like that
    do this:
    val start = new DateTime(2016, 1, 1, 0, 1, 1)
    sql"select * from measurement where end_interval >= ${start.toDate} limit 10"
    we never created a parameter for interpolation of org.joda.time.DateTime because we didn't want to add dependencies to relate. We would probably accept a PR adding direct support to DateTime via a module the way we have postgres support via a module though
    Drew O'Kane
    @drewokane
    hmmm, seems simple enough
    doesn't work though:
    scala> sql"select * from measurement where end_interval >= ${start.toDate} limit 10"
    res25: com.lucidchart.relate.InterpolatedQuery = select * from measurement where end_interval >= ? limit 10
    oh wait, nvm
    went through
    thanks @gregghz
    Gregg Hernandez
    @gregghz
    np!
    Murphy Randle
    @mrmurphy
    Hey friends, I'm just getting into SQL with Scala, and I'm using Relate. I'm running into an interesting situation where I've got this query:
    delete from management where key in (?);
    the actual source looks like this:
    sql"delete from $table where key in ($deleteKeys);"
    and $deletedKeys contains a string value
    in this case foo
    Gregg Hernandez
    @gregghz
    what is table? you might be subject to an sql syntax error with that usage
    Murphy Randle
    @mrmurphy
    the strange behavior I'm seeing is that foo will sometimes be deleted, and sometimes it will remain while only its content is deleted
    it's nondeterministic
    oh interesting, it's a custom table
    I haven't run into any errors so far
    Gregg Hernandez
    @gregghz
    Hmm, okay. Usually interpolating table names is a mistake. It will get written out as delete from “management” where …. Those quotes usually are a syntax error, that’s why I brought it up
    anyway, your issue: what do you mean by “only its content is deleted”?