scala, Doobie, Postgres - how to continue application run if there is sql error during batch insert

107 Views Asked by At

I have a simple doobie batch insert:

def insertMe(data: List[SomeData]): ConnectionIO[Unit] = {
  insert("Insert into some_table (name, age) values (data.name, data.age)")(data)
}

private def insert](sql: String)(data: List[String]): ConnectionIO[Unit] = Update[String](sql).updateMany(data.toList).void

It works fine where all data is correct. But when I get incorrect data (for example name length to long), I got SQL error and everything fails. My goal is to continue application run even when error appears, obly log this info but do not abort it. I tried to do something like continueOnError, but Doobie does not have this one. How it is possible to handle error when one batch fails and continue?

0

There are 0 best solutions below