Questions tagged [doobie]

Doobie is a pure functional JDBC layer for Scala and Cats.

Doobie is a pure functional JDBC layer for Scala and Cats.

It is not an ORM, nor is it a relational algebra; it simply provides a principled way to construct programs (and higher-level libraries) that use JDBC.

http://tpolecat.github.io/doobie/

99 questions
17
votes
1 answer

Doobie and DB access composition within 1 transaction

Doobie book says that it's a good practice to return ConnectionIO from your repository layer. It gives an ability to chain calls and perform them in one transaction. Nice and clear. Now let's imagine we are working on REST API service and our…
Eugene Zhulkov
  • 505
  • 3
  • 13
15
votes
1 answer

How to read/write Timestamp in Doobie (Postgres)

How to read/write Timestamp in Doobie? I have a record class that contains a timestamp field. When I am trying to write it to the database or read it using doobie I get an error Cannot find or construct a Read instance for type. case class…
Lev Denisov
  • 2,011
  • 16
  • 26
14
votes
4 answers

Doobie update and insert case class syntax

Doobie can select * with a case class for convenient and correct parameter passing, but I don't see how to work in a similar way with update and insert. For example, given a case class like this: case class Course( sku: String, title: String, …
Mike Slinn
  • 7,705
  • 5
  • 51
  • 85
13
votes
1 answer

Running queries in parallel in Doobie

Is it possible to run multiple queries in parallel, using Doobie? I have the following (pseudo)queries: def prepareForQuery(input: String): ConnectionIO[Unit] = ??? val gettAllResults: ConnectionIO[List[(String, BigDecimal)]] = ??? def…
mdm
  • 3,928
  • 3
  • 27
  • 43
13
votes
3 answers

Scala doobie fragment with generic type parameter

I am trying to abstract inserting objects of different types into sql tables of similar structure. Here's what I'm trying to do: class TableAccess[A : Meta](table: String) { def insert(key: String, a: A): ConnectionIO[Unit] = { (fr"insert into…
Joe K
  • 18,204
  • 2
  • 36
  • 58
12
votes
1 answer

Doobie cannot find or construct a Read instance for type T

I'm using doobie to query some data and everything works fine, like this: case class Usuario(var documento: String, var nombre: String, var contrasena: String) def getUsuario(doc: String) = sql"""SELECT documento, nombre, contrasena FROM…
santiromf
  • 123
  • 1
  • 6
9
votes
2 answers

Doobie - lifting arbitrary effect into ConnectionIO CE3

I am trying to migrate project from cats-effect 2 to cats-effect 3, i am using doobie for interacting with database. Previously i could lift ConnectionIO to IO as it was described, but with the upgrade i didn't find any implementation of…
poweright
  • 93
  • 5
9
votes
1 answer

Experiencing deadlocks when using the Hikari transactor for Doobie with ZIO

I'm using Doobie in a ZIO application, and sometimes I get deadlocks (total freeze of the application). That can happen if I run my app on only one core, or if I reach the number of maximum parallel connections to the database. My code looks…
fanf42
  • 1,828
  • 15
  • 22
9
votes
1 answer

Doobie transact over a list of ConnectionIO programs

Let's say I have a list of Doobie programs (all with Unit type parameters, fwiw): val progList: List[ConnectionIO[Unit]] = prog1 :: prog2 :: ... :: Nil Is there any way I can run them in one transaction? A for-comprehension won't work here, because…
Lasf
  • 2,536
  • 1
  • 16
  • 35
7
votes
1 answer

Is it okay to use "unsafeRunSync()" in Cats-Effects?

I am using Doobie and in the examples that I found, it uses unsafeRunSync, like: sql"select name from country" .query[String] // Query0[String] .to[List] // ConnectionIO[List[String]] .transact(xa) // IO[List[String]] …
7
votes
1 answer

How to create Async[Future] from Async[IO]

I am trying to implicitly add Async and Sync in my code for doobie repository. The Sync and Async[F] works fine IO. I want to convert them to Future and facing problem I have tried to create my own Aync from IO def futureAsync(implicit F:…
user11034858
  • 81
  • 1
  • 4
7
votes
2 answers

How to execute list of string SQL statements against a PostgreSQL db in Scala using doobie?

I am porting the following 10 lines of Python code to Scala: import psycopg2 def execute(user, password, database, host, port, *queries): connection = psycopg2.connect(user=user, password=password, host=host, port=port, database=database) …
pathikrit
  • 32,469
  • 37
  • 142
  • 221
6
votes
4 answers

Doobie - lifting arbitrary effect into ConnectionIO

I'm trying to send an email in the same transaction as inserting user into a database with Doobie. I know that I can lift IO into ConnectionIO by using Async[ConnectionIO].liftIO(catsIO) where catsIO: IO[String] But in my code I don't operate on IO,…
Leonti
  • 10,400
  • 11
  • 43
  • 68
6
votes
1 answer

Doobie batch update using generics

Can you make batch update in doobie with generic types? This code: def insertMany[T](ps: List[T]): Task[List[T]] = { val sql = "insert into person (name, age) values (?, ?)" Update[T](sql).updateMany(ps) } gives me: could not find implicit…
techkuz
  • 3,608
  • 5
  • 34
  • 62
5
votes
1 answer

Why does Doobie use free monad?

It seems that simple type Db[F[_], A] = Kleisli[F, Connection, A] type Transactor[DB[_], F[_]] = DB ~> F Сan be used to build functional JDBC layer as well
Sergey Alaev
  • 3,851
  • 2
  • 20
  • 35
1
2 3 4 5 6 7