-
Notifications
You must be signed in to change notification settings - Fork 2
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
[runtime] Support set map value by key #2
Comments
the main challenge is map requires a column name and two value, so we will have two Although AppendStringSlice has values, it used for binding as value, not in query, only col is used in query func (c *Context) AppendStringSlice(col StringSliceColumn, values ...string) SetValueStep {
appendList(c, col, values)
return c
} SetStringStringMapValue(col StringStringMapColumn, key string, value string) SetValueStep setFragments[i] = fmt.Sprintf("%s [?] = ?", col) |
it seems multiple func (c *Context) Prepare(s *gocql.Session) (*gocql.Query, error) {
// The reason why this is so dynamic is because of WHERE foo IN (?,?,?) clauses
// The factoring for an IN clause is bad, since we are storing an array into the value
// and using reflection to dig it out again
// This should be more strongly typed
placeHolders := make([]interface{}, 0)
for _, cond := range c.Conditions {
v := cond.Binding.Value
switch reflect.TypeOf(v).Kind() {
case reflect.Slice:
{
s := reflect.ValueOf(v)
for i := 0; i < s.Len(); i++ {
placeHolders = append(placeHolders, s.Index(i).Interface())
}
}
case reflect.Array:
{
// Not really happy about having to special case UUIDs
// but this works for now
if val, ok := v.(gocql.UUID); ok {
placeHolders = append(placeHolders, val.Bytes())
} else {
return nil, bindingErrorf("Cannot bind component: %+v (type: %s)", v, reflect.TypeOf(v))
}
}
default:
{
placeHolders = append(placeHolders, &v)
}
}
}
} |
- only support `col[?] = ?`, value binding should work, because there was `WHERE foo in (?,?,?)` so in `Prepare` cqlc would flat the slice before passing to gocql - #2 - [ ] TODO: need to test against a real database to see if it works
- when insert, use SetStringStringMap - when update, SetStringStringMapValue didn't work ... got gocql: expected 3 values send got 2
- BuildStatement is called by Exec, Prepare is called by Fetch, previously flatten is only applied in Prepare
summarize what need to be done in order to get this work (previous commit already works, need to tweak the test and clean up code) Actually it's all just runtime ....
|
Follow on relops#39
AppendSlice is the base point to follow
The text was updated successfully, but these errors were encountered: