pauljamescleary / scala-pet-store

An implementation of the java pet store using FP techniques in scala
Apache License 2.0
1.07k stars 209 forks source link

Enforce uniqueness constraints using doobie #48

Open pauljamescleary opened 6 years ago

pauljamescleary commented 6 years ago

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 commented 6 years ago

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.