-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
using of gocql.UnsetValue #202
Comments
Overall the proposal makes sense. Ad 1. Ad 2. |
|
Correct and correct. |
Ok, so I have the following plan:
@mmatczuk is it ok? |
I want to avoid taxing the main flow with more reflection and keep it simple in general. I had a look in the code. We could a decorator in Query, if the decorator is set call the decorator on bind. type Queryx struct {
...
Transformer func(name string, val interface{}) interface{} then On top of that you can build the UnsetValue transformer. |
I see your point but for me is not clear how to get info about tags in such transformer method. If we discard idea about using tags, then I understand how to do it. To be more json-like and use tags we can implement the following transformer method: type tranformerFn func(fi *reflectx.FieldInfo, val interface{}) interface{} And then rewrite tm := m.TypeMap(v.Type())
for i, name := range names {
fi, ok := tm.Names[name]
if ok {
val := reflectx.FieldByIndexesReadOnly(v, fi.Index).Interface()
if tf != nil { // transformerFn
val = tf(fi, val)
}
arglist = append(arglist, val)
}
} As you can see I made |
The point is you do not need the tags. |
Ok, got it. I will make a pr in several days |
Hi everyone! Recently we faced a following problem. In one of our processes we create a query by specifying ALL columns of a model struct and bind its fields by using method
BindStruct
. Some of the struct fields can benil
values and it leads to the problem that we generate ton of tombstones by explicitly sendingnull
values to Cassandra. Base drivergocql
hasgocql.UnsetValue
for unsetting value in statements that are already prepared. Unfortunately, creating custom type and adding methodgocql.MarshalCQL
doesn't solve the problem becausegocql
has different logic for set and unset values: we have to passgocql.UnsetValue
directly intoquery.Bind
method.To solve this problem we have some suggestions:
NilAsUnset
forQueryx
struct. It sets some flag and then methodbindStructArgs
bindsgocql.UnsetValue
for allnil
fields.BindCQL() interface{}
. Then in binding process check if value implements this interface. For these fields, instead of themselves, bind a return value ofBindCQL
method. As a result clients have flexibility in defining situations when custom fields should be considered as unset.What do you think guys? Can we workaround stated problem without adding new functionality? If it's impossible, then we're ready to implement any of the suggested methods by ourselves.
The text was updated successfully, but these errors were encountered: