-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split IsRelationNotFoundError and GetMissingSchemaFromIsRelationNotFo…
…undError and move to db_common rename rate steampipe_rate_limiter -> steampipe_plugin_limiter rename steampipe_connection_state -> steampipe_connection fix hcl range for all resources
- Loading branch information
1 parent
c85b6c3
commit a36dd1b
Showing
52 changed files
with
255 additions
and
154 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
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,38 @@ | ||
package db_common | ||
|
||
import ( | ||
"errors" | ||
"github.com/jackc/pgx/v5/pgconn" | ||
"regexp" | ||
) | ||
|
||
func IsRelationNotFoundError(err error) bool { | ||
_, _, isRelationNotFound := GetMissingSchemaFromIsRelationNotFoundError(err) | ||
return isRelationNotFound | ||
} | ||
|
||
func GetMissingSchemaFromIsRelationNotFoundError(err error) (string, string, bool) { | ||
if err == nil { | ||
return "", "", false | ||
} | ||
var pgErr *pgconn.PgError | ||
ok := errors.As(err, &pgErr) | ||
if !ok || pgErr.Code != "42P01" { | ||
return "", "", false | ||
} | ||
|
||
r := regexp.MustCompile(`^relation "(.*)\.(.*)" does not exist$`) | ||
captureGroups := r.FindStringSubmatch(pgErr.Message) | ||
if len(captureGroups) == 3 { | ||
|
||
return captureGroups[1], captureGroups[2], true | ||
} | ||
|
||
// maybe there is no schema | ||
r = regexp.MustCompile(`^relation "(.*)" does not exist$`) | ||
captureGroups = r.FindStringSubmatch(pgErr.Message) | ||
if len(captureGroups) == 2 { | ||
return "", captureGroups[1], true | ||
} | ||
return "", "", true | ||
} |
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.