-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
125 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package genji | ||
|
||
import ( | ||
"github.com/cockroachdb/errors" | ||
"github.com/genjidb/genji/internal/database" | ||
errs "github.com/genjidb/genji/internal/errors" | ||
) | ||
|
||
// IsNotFoundError determines if the given error is a NotFoundError. | ||
// NotFoundError is returned when the requested table, index, document or sequence | ||
// doesn't exist. | ||
var IsNotFoundError = errs.IsNotFoundError | ||
|
||
// IsAlreadyExistsError determines if the error is returned as a result of | ||
// a conflict when attempting to create a table, an index, a document or a sequence | ||
// with a name that is already used by another resource. | ||
func IsAlreadyExistsError(err error) bool { | ||
if errs.IsAlreadyExistsError(err) { | ||
return true | ||
} | ||
|
||
for err != nil { | ||
if cerr, ok := err.(*database.ConstraintViolationError); ok { | ||
switch cerr.Constraint { | ||
case "UNIQUE", "PRIMARY KEY": | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
err = errors.Unwrap(err) | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.