Is there a way to differentiate between errors returned by .Insert() etc? #1349
-
As part of test code, I'd like to, for example, attempt to insert a duplicate record to verify that unique constraints are working. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
SQLBoiler wraps errors from the database driver, so you need to look at the the documentation of your driver and see how to tell the errors apart. I wrote an article in 2021 about doing this for PostgreSQL using the There is also a wiki entry for If you're using MySQL, SQLite or SQL Server, the patters will be the same, but you'd need to find the underlying error type and use |
Beta Was this translation helpful? Give feedback.
SQLBoiler wraps errors from the database driver, so you need to look at the the documentation of your driver and see how to tell the errors apart.
I wrote an article in 2021 about doing this for PostgreSQL using the
github.com/lib/pq
driver. https://stephenafamo.com/blog/posts/handling-postgresql-errorsThere is also a wiki entry for
pgx
: https://github.com/jackc/pgx/wiki/Error-HandlingIf you're using MySQL, SQLite or SQL Server, the patters will be the same, but you'd need to find the underlying error type and use
errors.As
to get that concrete error.