Skip to content

Conversation

@cmoog
Copy link
Contributor

@cmoog cmoog commented Jan 16, 2020

Adds functionality described in #71

As is, the current implementation supports both sqlc.arg(ParamName) and :ParamName.

@cmoog cmoog changed the title adds support for custom sqlc.arg(MyParam) params adds mysql support for custom sqlc.arg(MyParam) params Jan 16, 2020
tests := []testCase{
testCase{
input: "INSERT INTO users (first_name, last_name) VALUES (?, ?)",
input: "INSERT INTO users (first_name, last_name) VALUES (?, sqlc.arg(UserLastName))",
Copy link
Collaborator

Choose a reason for hiding this comment

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

One thing I didn't mention in #71. I'm not sure we should allow mixing ? and sqlc.arg(). Thoughts?

Copy link
Collaborator

@kyleconroy kyleconroy left a comment

Choose a reason for hiding this comment

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

One small request for testing purposes.

Also, I don't see support for :param.

@cmoog
Copy link
Contributor Author

cmoog commented Jan 16, 2020

I just added the requested test changes. I also included an example in booktest for :param. Support for :param was included in the initial mysql PR.

@kyleconroy
Copy link
Collaborator

Thoughts about mixing parameter types? I think it will only lead to confusion.

@cmoog
Copy link
Contributor Author

cmoog commented Jan 16, 2020

Thoughts about mixing parameter types? I think it will only lead to confusion.

I can certainly imagine times when I'd want to only have one argument name override in complex queries with 5+ arguments. In those cases, mixing ? and sqlc.arg would be very convenient. With properly documented examples, I don't think it would be too confusing.

Copy link
Collaborator

@kyleconroy kyleconroy left a comment

Choose a reason for hiding this comment

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

The last thing we need to do is function call validation. If someone calls sqlc.arg with incorrect parameters, we want to return a helpful error message. Here are some of the mistakes that people might make:

sqlc.arg.name sqlc.arh(param) sqlc.arg(?) sqlc.arg('param') sqlc.arg(sqlc.arg(param)) 
@cmoog
Copy link
Contributor Author

cmoog commented Jan 16, 2020

Just added proper error messages for the last four examples. The first example already returns a reasonably helpful message from the column schema validation.

@kyleconroy kyleconroy merged commit f9d952d into sqlc-dev:master Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants