Skip to content

Support for naming hints via sqlc.arg in BETWEEN expressions #2277

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

Closed
dnwe opened this issue May 12, 2023 · 5 comments
Closed

Support for naming hints via sqlc.arg in BETWEEN expressions #2277

dnwe opened this issue May 12, 2023 · 5 comments
Labels
📚 mysql 📚 postgresql bug Something isn't working enhancement New feature or request 🔧 golang
Milestone

Comments

@dnwe
Copy link

dnwe commented May 12, 2023

What do you want to change?

Currently if you use a BETWEEN expression such as SELECT id, name, date FROM events WHERE date BETWEEN ? AND ?; then sqlc simply names the struct fields as Date and Date_2 a'la:

type GetEventByDateParams struct {
	Date   sql.NullTime
	Date_2 sql.NullTime
}

It would be great if naming hints could be passed to sqlc as-in LIKE expressions so you could put SELECT id, name, date FROM events WHERE date BETWEEN sqlc.arg(from_date) AND sqlc.arg(to_date); and that would result in the generated struct fields being FromDate and ToDate. At the moment if you attempt to do that it breaks the parser and the Params struct is omitted entirely (playground link)

What database engines need to be changed?

PostgreSQL, MySQL

What programming language backends need to be changed?

Go

@dnwe dnwe added enhancement New feature or request triage New issues that hasn't been reviewed labels May 12, 2023
@kyleconroy kyleconroy added bug Something isn't working 📚 mysql 📚 postgresql 🔧 golang and removed triage New issues that hasn't been reviewed labels Jun 6, 2023
@kyleconroy kyleconroy added this to the v1.19.0 milestone Jun 6, 2023
@Jille
Copy link
Contributor

Jille commented Jun 24, 2023

Kyle added this to the milestone, and I'd like to have the next release, so I wrote a PR :P

The change was small, but finding where to make it was harder :)

@SnoozeThis #2366

@SnoozeThis
Copy link

(https://snoozeth.is/E8ZK_PmKi-g) I will wait until #2366 is merged and then add a comment.

Jille added a commit to Jille/sqlc that referenced this issue Jun 24, 2023
@Jille
Copy link
Contributor

Jille commented Jun 24, 2023

I just realized I misread your feature request. I thought you wanted to have better default names than Date and Date_2. However, I made a drive-by fix that fixed reusing the same parameter number for both left and right and that probably fixed your actual request.

I've added a test case for your request to my PR.

@dnwe
Copy link
Author

dnwe commented Jun 26, 2023

@Jille perfect, testing with sqlc from your branch and it is working well, thank you!

As you mention, actually the "better defaults" behaviour actually satisfies the original bug without even needing the sqlc.arg support, but thanks for enabling that too

type GetEventByDateParams struct {
	FromDate time.Time
	ToDate   time.Time
}

@SnoozeThis
Copy link

Resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 mysql 📚 postgresql bug Something isn't working enhancement New feature or request 🔧 golang
Projects
None yet
Development

No branches or pull requests

4 participants