I have a table in my DB that the column names all start with caps (ie: FMR_Number, Primary_Value). The column name are out of my control. All the other columns in the DB (in other tables) are lower case. I have mapped a struct to the table but I keep getting a missing destination err from the query. I believe it is because the name mapper is set to ToLower (which is what it needs for everywhere else). I attempted to use this format
StructField string 'db:"RealColumnName"'
to specify the mapping explicitly but I get an illegal rune literal. When I go look at examples in other peoples code I see it being represented in the way I just tried it. If I reverse the ' and " to
StructField string "db:'RealColumnName'"
I don't get the illegal rune literal error but I do get the missing destination err. What am I doing wrong here? I am using sqlx.
My Struct
type pah struct {
FMR_Fund_Number string 'db:"FMR_Fund_Number"'
Business_Data_Date string 'db:"Business_Data_Date"'
Outbound_Composition_Code string 'db:"Outbound_Composition_Code"'
Composition_Sub_Code string 'db:"Composition_Sub_Code"'
Composition_Sub_Code_Description string 'db:"Composition_Sub_Code_Description"'
Position_Name string 'db:"Position_Name"'
Primary_Value float64 'db:"Primary_Value"'
Record_Order int 'db:"Record_Order"'
Tier_Indicator string 'db:"Tier_Indicator"'
}
My db call
func loadAssetAllocation() AssetAllocations {
pahGroup := []pah{}
pahQuery := "SELECT FMR_Fund_Number,Business_Data_Date,Outbound_Composition_Code,Composition_Sub_Code,Composition_Sub_Code_Description,Primary_Value,Tier_Indicator,Record_Order FROM PAH WHERE FMR_Fund_Number = \"312\" AND Outbound_Composition_Code = \"MDCAT\" AND Business_Data_Date = (SELECT Business_Data_Date FROM PAH ORDER BY Business_Data_Date DESC LIMIT 1) AND Composition_Sub_Code <> \"TAXADV\" ORDER BY Record_Order ASC"
assetAlloc := AssetAllocations{}
err := ffDB.Select(&pahGroup, pahQuery)
fmt.Println("pahQuery AssetAllocation error: ", err)
assetAlloc.AssetAll = pahGroup
return assetAlloc
}