fix jsonb output generator

When selecting content of a jsonb field the type per default is jsonb.
But we need to proper posgres type, so that the output can be parsed
properly.
Therefore make sure that the field has the proper output operator
attached.
This commit is contained in:
Gibheer 2021-05-07 11:35:48 +02:00
parent 554d6abf7f
commit f96f8ba4ed
1 changed files with 8 additions and 3 deletions

View File

@ -28,9 +28,9 @@ func FieldListToSelect(tableName string, fl types.FieldList, nameMap map[string]
res := []string{}
for _, name := range fl.Fields() {
if field, found := nameMap[name]; found {
res = append(res, fmt.Sprintf(`%s as %s`, field, name))
res = append(res, fmt.Sprintf(`%s as "%s"`, field, name))
} else {
res = append(res, fmt.Sprintf(`%s as %s`, nameToAttrPath(tableName, name), name))
res = append(res, fmt.Sprintf(`%s as "%s"`, nameToAttrPath(tableName, name), name))
}
}
return strings.Join(res, ",")
@ -45,7 +45,12 @@ func nameToAttrPath(tabName, name string) string {
for i, part := range parts {
parts[i] = fmt.Sprintf(`'%s'`, part)
}
return fmt.Sprintf("%s.attributes->%s", tabName, strings.Join(parts, "->"))
path := fmt.Sprintf("%s.attributes", tabName)
if len(parts) > 1 {
path += fmt.Sprintf("->%s", strings.Join(parts[:len(parts)-1], "->"))
}
path += fmt.Sprintf("->>%s", parts[len(parts)-1])
return path
}
// FieldMapToUpdate generates the necessary elements for an update.