Closed Faved closed 6 years ago
apologies, if this is the case, but should this really be on => https://github.com/vapor/postgresql ?
This is a broader issue with expectations of vapor/fluent. Fluent expects that you will only execute queries you know to be valid. Any errors that happen during the query are considered unexpected. In the case of a unique constraint, you should first ensure the model you are trying to save does not conflict with existing models before executing the save.
It's worth debating whether Fluent should be making those assumptions, but that should take place on vapor/fluent and it would probably be a patch update but more likely major version.
(Closing this issue here, but feel free to open discussion on vapor/fluent).
When a column in the database has a unique index, and another row is attempted to be saved, the error that is returned is of type
PostgreSQLDiagnosticResponse
currently, to be able to react upon this in a "nice" way in Vapor need to look at the error message to see if it contains something along the lines of "duplicate key"
It would be helpful if it would be possible to raise a specific error type based on a constraint failure, something like
PostgreSQLConstraintError
or something similar