Questions tagged [doobie]
Doobie is a pure functional JDBC layer for Scala and Cats.
doobie
105
questions
17
votes
1
answer
5k
views
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 ...
16
votes
1
answer
6k
views
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 ...
15
votes
4
answers
4k
views
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:
...
14
votes
1
answer
1k
views
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: ...
13
votes
3
answers
2k
views
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, ...
12
votes
1
answer
5k
views
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) =
...
10
votes
2
answers
3k
views
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 ...
9
votes
1
answer
2k
views
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 ...
9
votes
1
answer
2k
views
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 ...
7
votes
1
answer
3k
views
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 ...
7
votes
1
answer
3k
views
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[...
7
votes
2
answers
2k
views
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=...
6
votes
4
answers
4k
views
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: ...
6
votes
1
answer
2k
views
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)....
5
votes
2
answers
2k
views
Compose optional queries for for-comprehension in doobie?
I would like to run several queries in one transaction using a for-comprehension in doobie. Something like:
def addImage(path:String) : ConnectionIO[Image] = {
sql"INSERT INTO images(path) VALUES($...