Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Stacy Curl
@stacycurl
Thanks !
Rob Norris
@tpolecat
Sure, good luck!
Because AWS is a much bigger and much deeper API you may find that you’ll need to invent some new machinery.
Stacy Curl
@stacycurl
I’m cranking through the S3 api and it is big.
Rob Norris
@tpolecat
The basic idea of making the bottom layer map 1:1 with the underlying Java code is sound I think. Then derive safer stuff at a higher level.
It’s kept doobie relatively simple.
truongio
@truongio
Hi, is there any way to achieve this?
  def makePerson: Either[Throwable, Person] = ???
  implicit val read: Read[Person] = Read[(Long, String)].map { // I want something like .temap here
    case (age, name) => makePerson(age, name)  
  }
Swapnil S.
@Iamswapnil619

Hi ,

I have written a function to create db transactor code below using doobie hikari. :

def createTransactor(db: JDBC, pool_name: String , pool_size: Int): ZLayer[Blocking, Throwable, TransactorEnv] = ZLayer.fromManaged {
    val config = new HikariConfig()
    config.setDriverClassName(db.driver)
    config.setJdbcUrl(db.url)
    config.setUsername(db.user)
    config.setPassword(db.password)
    config.setMaximumPoolSize(pool_size)
    config.setPoolName(pool_name)
    for {
      rt <- Task.runtime.toManaged_
      transactor <- HikariTransactor.fromHikariConfig[Task](config, rt.platform.executor.asEC).toManagedZIO
    } yield transactor
  }

This code perfectly works with scala 2.12.14 but failed with scala 3.0.0 with below error :

[error] -- Error: /Users/sonawanes/Desktop/swapnil/etlflow-scala3/src/main/scala/db/Transactor.scala:29:3 
[error] 29 |  }
[error]    |   ^
[error]    |Exception occurred while executing macro expansion.
[error]    |java.lang.RuntimeException: TYPEREPR, UNSUPPORTED: class dotty.tools.dotc.core.Types$CachedRefinedType - RefinedType(AppliedType(TypeRef(ThisType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class doobie)),object util),module class transactor$)),class Transactor),List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class zio)),object package),type Task))),A,TypeBounds(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class zaxxer)),object hikari),HikariDataSource),TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class zaxxer)),object hikari),HikariDataSource)))
[error]    |    at izumi.reflect.dottyreflection.Inspector.inspectTypeRepr(Inspector.scala:96)
[error]    |    at izumi.reflect.dottyreflection.Inspector.buildTypeRef(Inspector.scala:22)
[error]    |    at izumi.reflect.dottyreflection.TypeInspections$.apply(TypeInspections.scala:10)
[error]    |    at izumi.reflect.dottyreflection.Inspect$.inspectAny(Inspect.scala:17)
[error]    |
[error]    | This location contains code that was inlined from Transactor.scala:29
[error]    | This location contains code that was inlined from Tags.scala:141

Any idea what i am doing wrong here ?

Rob Norris
@tpolecat
Looks like a compiler bug.
Rob Norris
@tpolecat
Or a zio macro bug.
Rob Norris
@tpolecat
I'm no longer monitoring this channel. Please move to https://sca.la/typeleveldiscord
discobaba
@uncleweirdo_twitter
Rob Norris
@tpolecat
I'm no longer monitoring this channel. Please switch to Typelevel Discord at https://sca.la/typeleveldiscord
Lawrence Wagerfield
@ljwagerfield
Given a case class Foo(..) and a Meta[Foo] that maps to a jsonb, how do I get a Meta[Array[Foo]] that maps to a jsonb[]? It doesn't seem to come "for free", leading me to believe there's a utility method somewhere for producing a Meta[Array[A]] from a Meta[A]..
dan-ilin
@dan-ilin

hi i'm trying to upgrade my project to use doobie version 0.13.4. i started getting this error on every sql query that i have defined in the project (via the sql interpolator):

java.lang.ClassCastException: doobie.util.fragment$Fragment cannot be cast to doobie.syntax.SqlInterpolator$SingleFragment

does anyone know what could be causing this exception?

Geovanny Junio
@geovannyjs
Deprecated. Please move to https://sca.la/typeleveldiscord
sanjivsahayamrea
@sanjivsahayamrea

Hi all, is there a way to try multiple Get decoders in the form:

Get[XYZ] = Get[Int].temap(....) orElse Get[Long].temap(...) orElse Get[String].temap(...)

We have a scenario where we have very similar queries that differ across tables because there is a boolean field encoded in different ways at the DB level.

1 reply
Circe has something like this:
 or[AA >: A](d: => Decoder[AA]): Decoder[AA]
sanjivsahayamrea
@sanjivsahayamrea
Unfortunately we can't change the db column types :(
Brandon Brown
@brbrown25
Question, with cats effect 2 I have some code like currentTime <- Async[ConnectionIO].liftIO(clock.realTime(MILLISECONDS)) I'm not exactly sure how I would convert that to cats effect 3 my initial naive approach was WeakAsyncConnectionIO.pure(clock.realTime.map(_.toMillis)) but that gives me an IO[ConnectionIO[Long]] and not ConnectionIO[Long] I then thought of clock.realTime.map(_.toMillis).to[ConnectionIO] but that requires an implicit LiftIO[ConnectionIO]
Any pointers would be greatly appreciated
jatcwang
@jatcwang:matrix.org
[m]

Or if possible try abstracting over the column type in your case class.

case class QueryResult[A](
  id: String,
  value: A
)

and then you can fr"...".query[QueryResult[Int]] fr"...".query[QueryResult[Long]] etc depending on the table

PsyfireX
@PsyfireX
import doobie.implicits._
import doobie.util.{Put, Read}
import org.scalatest.freespec.AnyFreeSpec

case class TempId2(id: Long, targetType: String)

trait TempId {
  val id: Long
  val targetType: String
}

object TempId{
  def apply(_id: Long, _targetType: String): TempId = new TempId {
    override val id: Long = _id
    override val targetType: String = _targetType
  }

  implicit val put: Put[TempId] = ???

  implicit val read: Read[TempId] = ???
}

object TempDao {
  case class Row(
    temp1: TempId,
//    temp1o: Option[TempId],
    temp2: Option[TempId2],
    temp2o: Option[TempId2],
  )

  read[Row]()

  def read[R: Read](): Unit = ???
}

Uncommenting the temp1o line results in the following:

Cannot find or construct a Read instance for type:

  ai.tagr.tagrdaos.daos.content.TempDao.Row

Along with the standard error about Refer to Chapter 12 of the book of doobie for more information.

It appears the issue is related to having an Option of a trait ... there is a read instance for the trait, and the trait is fine if it's not inside an option.

Any ideas?
PsyfireX
@PsyfireX
Oh, I think it might have something to do with Read vs Get
Maxim Ivanov
@redbaron
Hi All. I am trying to retry transaction on certain SQL codes. For queries returning ConnectionIO I managed to do that with exceptSomeSqlState, but it doesn't compile for queries returning Stream. What would you recommend to get it working?
import doobie._
import doobie.implicits._
import cats.implicits._
import doobie.postgres.sqlstate.class40


// this is how I retry queries returning ConnectionIO
def insertManyWithRetry[P: Write](
    q: doobie.Update[P],
    elems: List[P]
): ConnectionIO[Int] = {
  q.updateMany(elems)
    .exceptSomeSqlState({
      case class40.TRANSACTION_ROLLBACK |
          class40.TRANSACTION_INTEGRITY_CONSTRAINT_VIOLATION |
          class40.SERIALIZATION_FAILURE |
          class40.STATEMENT_COMPLETION_UNKNOWN | class40.DEADLOCK_DETECTED => {
        HC.rollback *> insertManyWithRetry(q, elems)
      }
    })
}

// trying to do the same for Stream[ConnectionIO, _]
def insertManyReturningWithRetry[K: Read, P: Write](q: Update[P], elems: List[P], columns: Seq[String]): fs2.Stream[ConnectionIO, K] = {
   q.updateManyWithGeneratedKeys(columns: _*)(elems).exceptSomeSqlState({
     case class40.TRANSACTION_ROLLBACK |
          class40.TRANSACTION_INTEGRITY_CONSTRAINT_VIOLATION |
          class40.SERIALIZATION_FAILURE |
          class40.STATEMENT_COMPLETION_UNKNOWN |
          class40.DEADLOCK_DETECTED => {
       // Doesn't work, because ConnectionIO[Unit] doesn't compose with Stream[ConnectionIO, K]
       HC.rollback *> insertManyReturningWithRetry(q, elems, columns)
     }
   })
 }
1 reply
jatcwang
@jatcwang:matrix.org
[m]
I'm unsure what the JDBC behaviour is around streams though if an error happened, so you'll need to test that it actually works too
Meriam Lachkar
@mlachkar

Hello, I have a question about Read Instance asnd how they compose.

  final case class Full(dependency: NewDependency, release: Option[NewRelease])
  //  I have a custom reader for NewRelease 
  // But I notice that Read[Full] uses a generic/derived reader for NewRelease`

So the code compiles fine, but reading fails, since it's not using my custom reader .
Right now to avoid this , I have re-written a Reader for Full, which copies the NewRelease reader with some differences to deal with the option.

      implicit val fullReader: Read[Full] = Read[(NewDependency, Option[String], ..........).map...

I am doing something wrong ? How can I fix this please ? thanks

Geovanny Junio
@geovannyjs
Deprecated. Please move to https://sca.la/typeleveldiscord
Meriam Lachkar
@mlachkar
thanks !
Nik
@your-psychiatrist:ellipsen.net
[m]
Can i use doobie to deserialize rows to case classes in scala 3? the docs suggest i need shapeless but that didnt build w/ scala 3 for me ad hoc.. figure'd i'd ask here first before wasting an hour on this (shapeless-3 seems to at least build)
Nik
@your-psychiatrist:ellipsen.net
[m]
found out that i'm gonna have to supply my own Get and Read instance :/ but it seems to work at least
peterstorm
@peterstorm:matrix.org
[m]
I’ve just used Circe Decoders and Encoders for my case classes and Doobie, and that seems to work fine
micky44
@Micky44Scoll_twitter
Hi, guys how can i write doobie with a custom enum list on scala 3?
jatcwang
@jatcwang:matrix.org
[m]
@Micky44Scoll_twitter: What do you mean by custom enum list? Can you give an example? :)
micky44
@Micky44Scoll_twitter

i.g, i have a custom enum list on database like

implicit val animalArray: Meta[Array[Animal]] = ???

how i can implement animalArray ?
when Animal is a database enum like

enum Animal:
  case Cat, Dog, Horse
end Animal

implicit val metaAnimal: Meta[Animal] = pgEnumString("animal_type", Animal.valueOf, _.toString)
jatcwang
@jatcwang:matrix.org
[m]
@Micky44Scoll_twitter: how are you storing these values in the db? What is the db column type?
micky44
@Micky44Scoll_twitter
@jatcwang:matrix.org i'm using Enum column type like
CREATE TYPE animal_type AS ENUM ('Cat', 'Dog', 'Horse');
jatcwang
@jatcwang:matrix.org
[m]
@Micky44Scoll_twitter: have you seen https://tpolecat.github.io/doobie/docs/11-Arrays.html? If you query that column as List[Animal] I think it should work.
Failing that, try querying something like SELECT 'Cat' :: animal_type and see if it maps into Animal correctly. If not it suggests that your implicit Meta[Animal] isn't in scope
(Looking at your scala 3 type definition, you probably want to put the Meta instance in the companion object of Animal?)
ruslan
@unoexperto

How do I quote brackets in doobie string interpolator ? I have case-sensitive column name in PSQL and I'm not sure how to properly write query for it. I tried this

sql"select nconst, \"birthYear\" from name_basics limit 10"

but I get Exception in thread "main" org.postgresql.util.PSQLException: ERROR: syntax error at or near "\" runtime error.

2 replies
Greg Fisher
@gnfisher
Doobie is upset that I am including columns in my select that I am not including in the case class the results are being read into. These are two similiarity(..) "columns" used for sorting but I don't need the data outside of that. Is there something I can do differently that doesn't including writing a READ for the case class?
jatcwang
@jatcwang:matrix.org
[m]
@gnfisher: Do another SELECT around it is the easiest way I can think of. Or you can query into an HList, drop the columns you don't need, and then convert that HList into your case class but that comes with bandwidth/performance cost ofc
jatcwang
@jatcwang:matrix.org
[m]
@unoexperto: he doesn't monitor this channel. Can you provide a minimal repo reproducing the problem? My guess is that something isn't being escaped properly in your code leading to the \ char in the SQL statement
ruslan
@unoexperto

@jatcwang:matrix.org Too bad. Rob used to be very active here. Where is he now ?

As per sample project it's located here
https://github.com/unoexperto/scala3-example-project/blob/main/src/main/scala/Main.scala
I just took official Scala 3 sample project and added few lines of doobie code.

jatcwang
@jatcwang:matrix.org
[m]
@unoexperto: he hangs out around typelevel discord but I can take a look first
ruslan
@unoexperto
@jatcwang:matrix.org Thanks!
jatcwang
@jatcwang:matrix.org
[m]
sql"""select nconst, "birthYear" from name_basics limit 10""" works @unoexperto
Arne Claassen
@sdether
Been away from Doobie for a while and trying to find a good pattern for Akka integration. The two obvious ways from IOConnection to ActorRef are:
1) unsafeToFuture and pipe the future and use onComplete to pipe it back to ActorRef
2) Create a pool of DB actors each with a connection, that use unsafeRunSync to block on the incoming message and reply back to ActorRef
Is there another way to run transactions on their own threadpool with a callback that can send the results to ActorRef?
thx
Dmitriy Kuzkin
@kuzkdmy

Hi, looks like a bug, before request it will be happy to get some assistance here. Thanks

Read not derived, next code results in such error

Cannot find or construct a Read instance for type:
  com.test.Main.DataWrapper2
But derivation works with simple Read[NewTypeWrapper]
package com.test

import doobie._
import doobie.postgres.implicits._
import io.estatico.newtype.macros.newtype

object Main extends App {
  @newtype case class NewTypeWrapper(value: Int)
  object NewTypeWrapper {
    implicit val read: Read[NewTypeWrapper] = Read[Int].map(NewTypeWrapper(_))
  }
  case class DataWrapper(one: NewTypeWrapper)
  case class DataWrapper1(list: List[Int])
  case class DataWrapper2(list: List[NewTypeWrapper])

  val t = NewTypeWrapper(1)
  println(Read[NewTypeWrapper])
  println(Read[DataWrapper])
  println(Read[DataWrapper1])
  println(Read[DataWrapper2])
}