Skip to content

Commit

Permalink
Add alternate ValidateSqlQueries which, unlike ValidateSqlQuery, does…
Browse files Browse the repository at this point in the history
… not consider multiple statements in one query to be an error.
  • Loading branch information
ncabatoff committed Sep 13, 2024
1 parent 5f05ce8 commit 55a93ea
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/vet/vet.go
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,25 @@ func ValidateSqlQuery(ctx VetContext, queryStr string) ([]QueryParam, error) {
return params, err
}

func ValidateSqlQueries(ctx VetContext, queryStr string) ([][]QueryParam, error) {
var ret [][]QueryParam

tree, err := pg_query.Parse(queryStr)
if err != nil {
return nil, err
}

for _, s := range tree.Stmts {
params, _, err := validateSqlQuery(ctx, s.Stmt)
if err != nil {
return nil, err
}
ret = append(ret, params)
}

return ret, nil
}

func validateSqlQuery(ctx VetContext, node *pg_query.Node) ([]QueryParam, []ColumnUsed, error) {

switch {
Expand Down

0 comments on commit 55a93ea

Please sign in to comment.