Closed nigelainscoe closed 2 years ago
Hello and thank you for opening this issue. I am sad to hear that it took you a while to debug. Let's improve it together if possible.
Here are my considerations:
pkg.go.dev
pkg.go.dev
already contains a dedicated paragraph for struct field mapping: https://pkg.go.dev/github.com/georgysavva/scany/dbscan#hdr-Mapping_struct_field_to_database_column:
By default, to get the corresponding database column dbscan translates struct field name to snake case. To override this behavior, specify the column name in the
dbfield tag. In the example above User struct is mapped to the following columns: "user_id", "first_name", "email".
The docs contain an example that even includes an Email
field just as you provided.I totally understand that even with all those counts that I listed above it might be not clear in some cases. I would be positive if you submit a PR where you update the documentation in pkg.go.dev
in your words.
Please make clear the use of the db tag on fields within structs in the README doc. It is not at all obvious. E.g.
type Simple struct { Email string
db:"Email"}
Is required where the name of the field being returned from the database is Email as opposed to email. It took me a long time to debug why dbscan was throwing
scany: column: 'Email': no corresponding field found, or it's unexported
when I could clearly see "Email" as a field in my struct and a corresponding "Email" field in my select statement.I know it's alluded to in the pkg.go.dev docs but it's not obvious even there.
Or maybe I should just do a PR?