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
5
votes
2 answers

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($path)".update.withUniqueGeneratedKeys('id',…
janne
  • 131
  • 1
  • 6
4
votes
1 answer

WIth doobie, how do I map Scala case class to postgresql column with type tstzmultirange?

So e.g. I create the table vacations in postgres: create table if not exists vacations ( person text primary key, vacations tstzmultirange not null ) And on the Scala side, I have: case class Interval(start: Instant, end: Instant) case class…
4
votes
0 answers

PostgreSQL Error with Doobie: PSQLException: The column index is out of range: 3, number of columns: 2

I am practicing with Scala, Doobie and PostgreSQL. The database is within a Docker container. I am able to post and update jobs but unable to GET all posts. I keep getting the below error. I have researched other similar questions but my differs as…
Ry2254
  • 859
  • 1
  • 10
  • 19
4
votes
1 answer

provide Get instance for Seq

For instance, I have some entities with some params, and two database tables, representating this entities: entity param ╔════╦═════════╗ ╔═══════════╦════════╗ ║ id ║ name ║ ║ entity_id ║ value ║ ╠════╬═════════╣ …
Oleg
  • 899
  • 1
  • 8
  • 22
4
votes
1 answer

How to pass complete query as a parameter

I get a query from gitlab ci and I want to execute it. If I hardcode the query is the sql"""""" syntax it works. But I want to pass it as a variable(the whole query). the SqlInterperator doesn't take the value of the variable and hence returns an…
Sam
  • 497
  • 1
  • 10
  • 34
4
votes
1 answer

SQL `NULL` read at column 1 (JDBC type null) but mapping is to a non-Option type

I want select the max value using this query (all fields in table are not null): dc.run(quote { query[SchemaInfo] .filter(_.subjectName == lift(subject)) .map(_.version) .max }).map(_.map(_ + 1).getOrElse(1)) I know, that…
Nikita Ryanov
  • 1,520
  • 3
  • 17
  • 34
4
votes
0 answers

Doobie: create constant table with values

Postgres allows creation of constant tables for use in queries with this syntax: WITH names (id, name) AS (VALUES (1, 'ABC'), (2, 'BCD')) SELECT id FROM names or the inlined version: SELECT id FROM (VALUES (1, 'ABC'), (2, 'BCD')) AS t (id,…
Maths noob
  • 1,684
  • 20
  • 42
4
votes
1 answer

Doobie. Compose .update.withGeneratedKeys() and .update.run

Referencing to this question. I want to insert some entity by some condition. It can either be inserted or not. If the condition is true the entity is inserted. I want to insert some other data in various tables. It looks like this: val q =…
Oleg
  • 899
  • 1
  • 8
  • 22
4
votes
1 answer

How to get optional result in insert statements with Doobie?

I have an optional insert query: val q = sql"insert into some_table (some_field) select 42 where ...(some condition)" Running this query with: q.update.withUniqueGeneratedKeys[Option[Long]]("id") fails with Result set exhausted: more rows…
Oleg
  • 899
  • 1
  • 8
  • 22
4
votes
1 answer

How to connect to Hive using doobie

There is a jdbc driver for hive but seems not fully functioning. I used the default doobie Transactor to connect to it like val xa = Transactor.fromDriverManager[IO]( "org.apache.hive.jdbc.HiveDriver", url, username,…
KailuoWang
  • 1,304
  • 1
  • 12
  • 24
4
votes
1 answer

Doobie with Hikari setup

I want to get the hikari transactor setup to act just like the standard transactor val xa = HikariTransactor.newHikariTransactor[IO]( "com.mysql.jdbc.Driver", JdbcUrl, Username, Password ) sql"""select DISTINCT gcpProject FROM JobStatus""" …
Matthew Fontana
  • 3,790
  • 2
  • 30
  • 50
3
votes
2 answers

How I can insert case object as JSONB format via Doobie?

I use scala 2.13 and doobie 0.12.1 For example, I have case class case class UserInfo(name: String, age: Int, hobbies: Vector[String]) I want insert user info in column info as jsonb sql""" INSERT INTO users( id, …
John
  • 103
  • 1
  • 11
3
votes
1 answer

How to generate SQL statements dynamically using Doobie (scala)

I have the query: val sql = """select id, clientName from partnerClients where partnerName = ? """ I read partnerName from excel file and…
3
votes
0 answers

Doobie. Set connection timeout

How to set connection timeout using Doobie? For now, I am creating a new hikari transactor, and then configuring it: def buildTransactor(driver: String, uri: String, user: String, pwd: String, timeout:…
Oleg
  • 899
  • 1
  • 8
  • 22
3
votes
0 answers

Getting Error while querying to mysql with doobie

I have transactor below val transactor: Resource[IO, HikariTransactor[IO]] = for { ce <- ExecutionContexts.fixedThreadPool[IO](32) // our connect EC be <- Blocker[IO] // our blocking EC xa <-…