add missing table name
The table name was missing from the implementation of FieldsToJSON. This was also fixed in the tests.
This commit is contained in:
parent
88c271667b
commit
e9135c9c10
@ -43,9 +43,9 @@ func FieldListToSelect(tableName string, fl types.FieldList, nameMap map[string]
|
||||
func FieldsToJSON(table string, fields map[string]string) string {
|
||||
res := []string{}
|
||||
for key, val := range fields {
|
||||
res = append(res, fmt.Sprintf("'%s', %s", key, val))
|
||||
res = append(res, fmt.Sprintf("'%s',%s", key, val))
|
||||
}
|
||||
return fmt.Sprintf("jsonb_build_object(%s) || attributes", strings.Join(res, ","))
|
||||
return fmt.Sprintf("jsonb_build_object(%s) || %s.attributes", strings.Join(res, ","), table)
|
||||
}
|
||||
|
||||
// nameToAttrPath takes a dotted string and converts it into a json field path.
|
||||
|
@ -46,7 +46,18 @@ func TestJSONSelect(t *testing.T) {
|
||||
table string
|
||||
fields map[string]string
|
||||
out string
|
||||
}{}
|
||||
}{
|
||||
{
|
||||
"zoo",
|
||||
map[string]string{"foo": "foo", "bar": "bar", "zoo": "f.bar"},
|
||||
"jsonb_build_object('foo',foo,'bar',bar,'zoo',f.bar) || zoo.attributes",
|
||||
},
|
||||
{
|
||||
"f",
|
||||
map[string]string{"foo": "l.attributes->>'foo'", "zoo": "a.zoo"},
|
||||
"jsonb_build_object('foo',l.attributes->>'foo','zoo',a.zoo) || f.attributes",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
out := FieldsToJSON(test.table, test.fields)
|
||||
if out != test.out {
|
||||
|
Loading…
Reference in New Issue
Block a user