Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature sqlstate support #215

Merged
merged 2 commits into from
Oct 10, 2023

Conversation

alirezaarzehgar
Copy link
Contributor

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Add support for invalid column error translation

User Case Description

type Model struct {
	Field string
}

dsn := "host=localhost port=5432 user=user password=pass dbname=db sslmode=disable TimeZone=Asia/Tehran"
db, ـ := gorm.Open(postgres.Open(dsn), &gorm.Config{TranslateError: true})
db.AutoMigrate(&Model{})

var m Model
err = db.First(&m, "wrongfield = ?", "value").Error
if errors.Is(err, gorm.ErrInvalidField) {
	fmt.Println("Invalid Field")
} else if err != nil {
	fmt.Println("Unknown error")
}

* Add gorm.ErrInvalidField error for 42703 SQLSTATE.
* Add test for new supported error code.

Signed-off-by: alireza <alirezaarzehgar82@gmail.com>
new json fields names was same as struct field names.
It's default behavior of json package and we don't need them.

Signed-off-by: alireza <alirezaarzehgar82@gmail.com>
@jinzhu jinzhu merged commit b3c309a into go-gorm:master Oct 10, 2023
1 check passed
PuneetPunamiya pushed a commit to PuneetPunamiya/postgres that referenced this pull request Jan 17, 2024
* feat: add error code for undefined column

* Add gorm.ErrInvalidField error for 42703 SQLSTATE.
* Add test for new supported error code.

Signed-off-by: alireza <alirezaarzehgar82@gmail.com>

* refactor: remove unnecessary json struct tags

new json fields names was same as struct field names.
It's default behavior of json package and we don't need them.

Signed-off-by: alireza <alirezaarzehgar82@gmail.com>

---------

Signed-off-by: alireza <alirezaarzehgar82@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants