Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Alexis Hernandez
@AlexITC
Rob Norris
@tpolecat
I’m working on better logging right now but for now that’s how to do it.
Alexis Hernandez
@AlexITC
the logs are actually nice, the downside is requiring to change the source to get them displayed, i was hoping to just update a log level in logback
Rob Norris
@tpolecat
The way I’m setting it up transact will have a Log4cats Logger constraint so it will append to whatever log is in scope
This way you can pass a logger with a correlation id or something.
Igor Rumiha
@irumiha
If it helps anyone, for sql statement logging we are using https://github.com/p6spy/p6spy in our dev environment. Works well.
Rob Norris
@tpolecat
Oh cool. I have been looking for a working one of those.
Kai
@neko-kai
@lbialy The API for fundamentals-reflection is stable and it doesn’t depend on anything except scala-reflect, so it’s already a micro-library, basically...
Dermot Haughey
@hderms
@Daenyth yeah that PR was basically the missing link imo when I was looking at how to do this before
Gavin Bisesi
@Daenyth
I'll try to get the test fixed up
in the mean time the code should work
The error is definitely in the test and not the code as we use it heavily in prod
m4dc4p
@m4dc4p

@tpolecat when I write this line, wtf am I saying?

     Put.Advanced.many(NonEmptyList.of(JdbcType.Null), NonEmptyList.of("timestamp with time zone", "int4"), (ps, idx, _) => { ps.setNull(idx, java.sql.Types.NULL) }, (_, _, _) => ())

Specifically, what does JdbcType.Null mean, and what does the NEL do?

For context, I used this definition to define a datatype that always returns NULL and writes NULL .
Kai
@neko-kai
@tpolecat What do you think of tpolecat/doobie#1035
tpolecat/doobie#1045
Does something like that have a change to be merged?..
Rob Norris
@tpolecat
@kaishh I haven't had a chance to review those but they sound good in principle.
Thanks for your work, I will try to have a look over the weekend.
Kai
@neko-kai
@tpolecat :+1:
Rob Norris
@tpolecat
We're experimenting with a Discord channel. Join here https://discord.gg/2N8ZBR
flindskog
@flindskog
Hi! Is there a way to compose tasks to participate in a parent transaction? I.e. the following tasks are separate transactions, but want them (occasionally) to be part of a parent transaction.
for {
    a <- task1
    b <- task2
    c <- task3
} yield (a, b, c)
Note that each of these performs its own transact, so they are not ConnectionIO:s
Rob Norris
@tpolecat
No. If you want to compose programs sub-transactionally leave them in ConnectionIO.
flindskog
@flindskog
Ok, got it. Thank you!
Rob Norris
@tpolecat
In general you want to stay in ConnectionIO as long as you can to promote this kind of composition.
Frederick Cai
@zhenwenc
@tpolecat the discord link is invalid
Rob Norris
@tpolecat
@zhenwenc sorry, here is one that doesn't expire https://discord.gg/zzF8CdM
m4dc4p
@m4dc4p
Is there an example of Get for a Vector I can look at? Trying to read a Vector[Foo] (where foo is a case class).
Rob Norris
@tpolecat
What is the column type?
Get reads a single column value.
m4dc4p
@m4dc4p
Its an array column
Actually an array of ROW values
m4dc4p
@m4dc4p
e.g., this fails to compile:
object P {
  import doobie._
  import doobie.implicits._
  import doobie.postgres.implicits._

  case class Bar(a: Int)

  def q = sql"".query[Vector[Bar]]
}
with Cannot find or construct a Read instance for type Bar
Matthew Tovbin
@tovbinm

Howdy folks. I have a bit of a long question on how to handle struct types with Doobie & Postrgres.

Assume the following toy schema:

CREATE TYPE public."Payment" AS (
      "cardId" character varying,
      "expiration" character varying
)
 CREATE TYPE public."User" AS (
     email character varying NOT NULL
     payment public."Payment"
)

Represented with classes:

case class Payment(cardId: String, expiration: String)
case class User(email: String, payment: Option[Payment])

Then when writing a query:

sql"""INSERT INTO public."User" (email, payment) VALUES (${user.email}, ${user.payment})"""

We get and error that Put and Get instances are not found in scope. So I tried providing one as follows and the only way I made it work is with Put and Get for Advanced.one as follows:

implicit val pGet: Get[Payment] =
    Get.Advanced
      .one[PGobject](
        JdbcType.Struct,
        NonEmptyList.of("\"Payment\""),
        (rs, n) => {
          rs.getObject(n) match {
            case null        => null
            case a: PGobject => a
            case a           => throw InvalidObjectMapping(classOf[PGobject], a.getClass)
          }
        }
      ).temap[Payment] { o =>
        // parse Payment from o.getValue which is a string!
      }

  implicit val pPut: Put[Payment] =
    Put.Advanced
      .one[PGobject](
        JdbcType.Struct,
        NonEmptyList.of("\"Payment\""),
        (ps, n, a) => ps.setObject(n, a),
        (rs, n, a) => rs.updateObject(n, a)
      ).tcontramap[Payment] { v =>
        val o = new PGobject
        o.setType("\"Payment\"")
        o.setValue(s"(${v.cardId},${v.expiration})")
        o
      }

Is there a better way?!? Thank you in advance!

Frederick Cai
@zhenwenc
@tpolecat sorry for the late reply, thank you for the discord link! 🍻
@m4dc4p I think what you want is:
def q = sql"".query[Bar].to[Vector]
Rob Norris
@tpolecat
@m4dc4p there is no support for arrays of structs in the Postgres driver so I don’t think it’s possible to read an array of row types. If you can get it to work with raw JDBC we can get it to work in doobie but I would start there.
@tovbinm there is no direct support for structs because driver support is so sketchy, but it looks like maybe that could be generalized in the Postgres case. Can you open an issue with your example?
Abhishek Srivastava
@abhishes_twitter
What is wrong with this code?
        val likeClause = fr"col_name like %$foo"
        val snapshotDay = fr"snapshot_day='2019-10-14'"
        (fr"""
            select distinct col_name from mytable """ ++ whereAnd(likeClause, snapshotDay)).query[String].to[List]
Im getting error Invalid operation: syntax error at or near "%" [error] Position: 112;
Rob Norris
@tpolecat
You need ${"%" + foo}
So the entire pattern becomes a parameter.
Abhishek Srivastava
@abhishes_twitter
thanks. yes.
that works
m4dc4p
@m4dc4p
@tpolecat @zhenwenc thanks for getting back to me. I ended up converting the postgres array to a JSON array and decoding it via a custom Get instance (Get[Vector[Bar]] = Get[Json].map(...)`). Not super happy with that but did the trick.
Will skunk have native support for postgres arrays? :)
Rob Norris
@tpolecat
Yes
And structs.
And arrays of structs.
Etc.