scala-pet-store icon indicating copy to clipboard operation
scala-pet-store copied to clipboard

Enforce uniqueness constraints using doobie

Open pauljamescleary opened this issue 7 years ago • 1 comments

The way we check if something exists, or is unique, is done via Validations.

The correct way to do this in a SQL db application is to enforce those invariants in the data base using unique constraints.

Consider using http://tpolecat.github.io/doobie/docs/09-Error-Handling.html as a guide for handling these kinds of exceptions.

pauljamescleary avatar Dec 24 '17 15:12 pauljamescleary

Actually unsure if we should do this or not tbh. Happy to get other people's thoughts on it.

Assuming all data was in a single JDBC database, this seems like the best approach. However, I have built systems with heterogeneous backing stores where this would not be possible.

Also, unless I have other ways to demonstrate dependent validations (i.e. validations requiring external data), then these serve as a good use case for those.

pauljamescleary avatar Dec 25 '17 15:12 pauljamescleary