Skip to content

parseQuery: Return either a query or an error #178

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

Merged
merged 5 commits into from
Dec 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/dinosql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func parseQuery(c core.Catalog, stmt nodes.Node, source string) (*Query, error)
}
raw, ok := stmt.(nodes.RawStmt)
if !ok {
return nil, nil
return nil, errors.New("node is not a statement")
}
switch n := raw.Stmt.(type) {
case nodes.SelectStmt:
Expand All @@ -382,7 +382,7 @@ func parseQuery(c core.Catalog, stmt nodes.Node, source string) (*Query, error)
}
case nodes.UpdateStmt:
default:
return nil, nil
return nil, fmt.Errorf("parseQuery: unsupported statement type: %T", n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a note that here and above you should file an issue if you hit this error because it's easy to see someone generating code that (should be) valid but hitting an edge case here because we haven't thought about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense because with #179, these edge cases shouldn't be hit at all. Now the user gets the following error if it happens though:

parseQuery: unsupported statement type: pg_query.CreateStmt - feel free to file an issue on GitHub

}

rawSQL, err := pluckQuery(source, raw)
Expand Down