First of all, thank you for this amazing package! You've saved me a TON of work.
One call out I have is, this package doesn't seem to implement the database/sql/driver.Valuer
and database/sql/driver.Valuer
interfaces for SubdivisionCode
.
How I arrived at this conclusion:
I have an API that takes in POST requests from the client, marshals it into a Go struct, then uses Gorm to store that struct model in a Postgres DB.
The struct has a field of type countries.SubdivisionCode
, and the package is able to correctly unmarshal it into the struct as a string (i.e. "US-MA" --> "Massachusetts"). It also correctly inserts it into the DB as "Massachusetts." However, when I select that record from the DB and unmarshal it into a Go struct, the subdivision code field reads as "Unknown".
✅ POST request:
✅ Unmarshal the Request Body with Fiber into a Struct:
✅ Insert Into the DB:
❌ Select that Record from DB: Now the field shows up as Unknown.
On a related note, what function is causing "US-MA" to be read in as "Massachusetts" and when is that function called? Is there a way to insert it into the DB as a "US-MA"?
EDIT:
Using fmt.Printf("%+v")
printed the field as "Massachusetts"
(I'm guessing the package uses the String() method to do so), but when I just use fmt.Printf("%#v")
, it outputs as "US-MA".
Still, how is it getting inserted into the DB as "Massachusetts" when it doesn't have an explicit driver.Valuer function?