Skip to content

Add new error for "Violation Check Constraint"#6992

Merged
jinzhu merged 1 commit intogo-gorm:masterfrom
anilsenay:err-check-constraint-violated
Apr 26, 2024
Merged

Add new error for "Violation Check Constraint"#6992
jinzhu merged 1 commit intogo-gorm:masterfrom
anilsenay:err-check-constraint-violated

Conversation

@anilsenay
Copy link
Copy Markdown
Contributor

@anilsenay anilsenay commented Apr 25, 2024

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

What did this pull request do?

Add new error for "Check Constraint Violation"

User Case Description

I added a check constraint in my table in PostgreSQL such as:
CONSTRAINT path_check CHECK (path ~ '^/[a-zA-Z0-9\-]+$')

When an error occurs when I try to add a new row to the table, I want to be sure that it is a rule violation error or another type of error.

if errors.Is(result.Error, gorm.ErrCheckConstraintViolated) {
  // handle check constraint violation error
}

Pull request for go-gorm/postgres: go-gorm/postgres#271

@jinzhu jinzhu merged commit ac59252 into go-gorm:master Apr 26, 2024
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.

2 participants