Database errors handling in gorm

Has anyone dealt with handling database errors in gorm?
I have two cases in my code where I need to exploit a base error: constraint or uuid validation.
(e.g. SQL Error [8169] [S0002]: Conversion failed when converting from a character string to uniqueidentifier.)
When I use the gorm: model-find, raw-scan methods, I get the expected results in positive run, butin negative run result.error doesn’t have a sql error (result.Error is nil), e.g. when I try to insert against a constraint or get where not valid uuid. I get this error in the console when I run a debug query there.
On the other hand, when I use exec (also sql.Exec), I get an error on a negative run, but the result of the positive run does not contain, or I can’t get the expected value.

Sorry for hussles - when I was extracting code, I found a solution. This is a combination of methods Exec and Find.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.