Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Care array value and struct value as a input value #178

Merged
merged 1 commit into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions internal/contentdata/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,14 @@ func (r *Repository) Query(ctx context.Context, tx *connection.Tx, projectID, da

values := []interface{}{}
for _, param := range params {
value, err := r.queryParameterValueToGoValue(param.ParameterValue)
if err != nil {
return nil, err
}
if param.Name != "" {
values = append(values, sql.Named(param.Name, param.ParameterValue.Value))
values = append(values, sql.Named(param.Name, value))
} else {
values = append(values, param.ParameterValue.Value)
values = append(values, value)
}
}
fields := []*bigqueryv2.TableFieldSchema{}
Expand Down Expand Up @@ -241,6 +245,32 @@ func (r *Repository) Query(ctx context.Context, tx *connection.Tx, projectID, da
}, nil
}

func (r *Repository) queryParameterValueToGoValue(value *bigqueryv2.QueryParameterValue) (interface{}, error) {
switch {
case len(value.ArrayValues) != 0:
arr := make([]interface{}, 0, len(value.ArrayValues))
for _, v := range value.ArrayValues {
elem, err := r.queryParameterValueToGoValue(v)
if err != nil {
return nil, err
}
arr = append(arr, elem)
}
return arr, nil
case len(value.StructValues) != 0:
st := make(map[string]interface{}, len(value.StructValues))
for k, v := range value.StructValues {
elem, err := r.queryParameterValueToGoValue(&v)
if err != nil {
return nil, err
}
st[k] = elem
}
return st, nil
}
return value.Value, nil
}

// zetasqlite returns []map[string]interface{} value as struct value, also returns []interface{} value as array value.
// we need to convert them to specifically TableRow and TableCell type.
func (r *Repository) convertValueToCell(value interface{}) (*internaltypes.TableCell, error) {
Expand Down