Skip to content

Commit

Permalink
Prevented column name ambiguity
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-asplin-met-no committed Dec 11, 2023
1 parent 43a765a commit da9b93f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions datastore/storagebackend/postgresql/getobservations.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ func getGeoFilter(inside *datastore.Polygon, phVals *[]interface{}) (string, err

type stringFieldInfo struct {
field reflect.StructField
tableName string
method reflect.Value
methodName string
}
Expand Down Expand Up @@ -252,21 +253,22 @@ func getObs(db *sql.DB, request *datastore.GetObsRequest, obs *[]*datastore.Meta

stringFieldInfos := []stringFieldInfo{}

addStringFields := func(s interface{}) {
addStringFields := func(s interface{}, tableName string) {
for _, field := range reflect.VisibleFields(reflect.TypeOf(s)) {
mtdName := fmt.Sprintf("Get%s", field.Name)
mtd := rv.MethodByName(mtdName)
if field.IsExported() && (field.Type.Kind() == reflect.String) && (mtd.IsValid()) {
stringFieldInfos = append(stringFieldInfos, stringFieldInfo{
field: field,
tableName: tableName,
method: mtd,
methodName: mtdName,
})
}
}
}
addStringFields(datastore.TSMetadata{})
addStringFields(datastore.ObsMetadata{})
addStringFields(datastore.TSMetadata{}, "time_series")
addStringFields(datastore.ObsMetadata{}, "observation")

for _, sfInfo := range stringFieldInfos {
patterns, ok := sfInfo.method.Call([]reflect.Value{})[0].Interface().([]string)
Expand All @@ -277,7 +279,8 @@ func getObs(db *sql.DB, request *datastore.GetObsRequest, obs *[]*datastore.Meta
}
if len(patterns) > 0 {
stringFilterInfos = append(stringFilterInfos, stringFilterInfo{
colName: common.ToSnakeCase(sfInfo.field.Name),
colName: fmt.Sprintf(
"%s.%s", sfInfo.tableName, common.ToSnakeCase(sfInfo.field.Name)),
patterns: patterns,
})
}
Expand Down

0 comments on commit da9b93f

Please sign in to comment.