Skip to content

Feature request: extend Strict Scan mode to also detect unmapped struct fields #472

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

Open
kblomster opened this issue Mar 25, 2025 · 2 comments
Labels

Comments

@kblomster
Copy link
Contributor

kblomster commented Mar 25, 2025

Is your feature request related to a problem? Please describe.
I was very happy to see the addition of Strict Scan mode in 2.13. It catches a relatively common type of mistake that we can't really catch in any other way.

There is a closely related problem that it does not catch, though - it catches the case where you're projecting columns that you end up not using, but it does not catch the case where the data structure you're mapping into is not being fully populated by the projections. At least in our codebase, this reverse problem is actually a bigger pain point because the Go zero values for structs are very good at concealing this problem.

We really love Jet, but one of our biggest pain points is actually how inscrutable the QRM appears, especially to people new to Jet. You get zero feedback from it, it just silently hands you structs with the wrong data in them.

Describe the solution you'd like
I'd love to see a Strict Scan-like feature that will panic and/or make some other noise if the mapping target is not fully populated by the query. Trivial example:

var target []struct {
	Foo string
	Bar int
}
stmt := jet.SELECT(
	jet.String("hello").AS("foo"))
// panic: target is not fully populated, missing field Bar
err := stmt.Query(db, &target)
@kblomster kblomster changed the title Extend Strict Scan mode to also detect unmapped struct fields Feature request: extend Strict Scan mode to also detect unmapped struct fields Mar 25, 2025
@go-jet
Copy link
Owner

go-jet commented Mar 26, 2025

Yeah, it makes sense. I guess we could add a new flag StrictFieldMapping.

@go-jet go-jet added the good first issue Good for newcomers label Mar 26, 2025
@go-jet
Copy link
Owner

go-jet commented Mar 26, 2025

As code of interest - at this line unuesed field is identified.
And for the tests - we can set this new StrictFieldMapping flag for either mysql or sqlite tests, since postgres tests are already run in StrictScan mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants