I have query which is having 15 columns. Which is written by dba team.
Rest api team like to give only 5 column to front end developer.
But sqlx scan it select ask for all columns.
How to avoid this case.
I have query which is having 15 columns. Which is written by dba team.
Rest api team like to give only 5 column to front end developer.
But sqlx scan it select ask for all columns.
How to avoid this case.
You could create a struct that’s a subset of those columns:
type WideStruct struct {
ColumnIDontCareAbout int
ColumnIDoCareAbout int
//...
}
func (w WideStruct) ToSubStruct() SubStruct {
return SubStruct{
ColumnIDoCareAbout: w.ColumnIDoCareAbout,
}
}
type SubStruct struct {
ColumnIDoCareAbout int
//...
}
The other easy option is: just use a custom MarshalJson:
You could also ditch sqlx for this query, and scan into local variables and just populate the properties you need on some struct.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.