Skip to content

Commit

Permalink
Update gocql version to v1.14.4
Browse files Browse the repository at this point in the history
  • Loading branch information
dkropachev committed Oct 10, 2024
1 parent 721e236 commit 151802c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
37 changes: 31 additions & 6 deletions change.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,11 @@ func (wnu *withNullUnmarshaler) UnmarshalCQL(info gocql.TypeInfo, data []byte) e

case gocql.TypeList, gocql.TypeSet:
if data == nil {
wnu.value = reflect.ValueOf(info.New()).Elem().Interface()
val, err := info.NewWithError()
if err != nil {
return fmt.Errorf("cannot create new instance of %s: %w", info, err)
}
wnu.value = reflect.ValueOf(val).Elem().Interface()
return nil
}

Expand All @@ -925,7 +929,11 @@ func (wnu *withNullUnmarshaler) UnmarshalCQL(info gocql.TypeInfo, data []byte) e
return err
}

lV := reflect.ValueOf(info.New()).Elem()
val, err := info.NewWithError()
if err != nil {
return fmt.Errorf("cannot create new instance of %s: %w", info, err)
}
lV := reflect.ValueOf(val).Elem()
for _, wnm := range lWnm {
lV.Set(reflect.Append(lV, reflect.ValueOf(wnm.derefForListOrMap())))
}
Expand All @@ -934,21 +942,34 @@ func (wnu *withNullUnmarshaler) UnmarshalCQL(info gocql.TypeInfo, data []byte) e

case gocql.TypeMap:
if data == nil {
wnu.value = reflect.ValueOf(info.New()).Elem().Interface()
val, err := info.NewWithError()
if err != nil {
return fmt.Errorf("cannot create new instance of %s: %w", info, err)
}
wnu.value = reflect.ValueOf(val).Elem().Interface()
return nil
}

// Make a map with withNullMarshallers
mapInfo := info.(gocql.CollectionType)
keyType := reflect.TypeOf(mapInfo.Key.New()).Elem()

keyVal, err := mapInfo.Key.NewWithError()
if err != nil {
return fmt.Errorf("cannot create new instance of %s: %w", mapInfo.Key, err)
}
keyType := reflect.TypeOf(keyVal).Elem()
mapWithWnuType := reflect.MapOf(keyType, reflect.TypeOf(withNullUnmarshaler{}))
mapWithWnuPtr := reflect.New(mapWithWnuType)
mapWithWnuPtr.Elem().Set(reflect.MakeMap(mapWithWnuType))
if err := gocql.Unmarshal(info, data, mapWithWnuPtr.Interface()); err != nil {
return err
}

resultMapType := reflect.TypeOf(info.New()).Elem()
mapVal, err := info.NewWithError()
if err != nil {
return fmt.Errorf("cannot create new instance of %s: %w", info, err)
}
resultMapType := reflect.TypeOf(mapVal).Elem()
resultMap := reflect.MakeMap(resultMapType)
iter := mapWithWnuPtr.Elem().MapRange()
for iter.Next() {
Expand All @@ -972,7 +993,11 @@ func (wnu *withNullUnmarshaler) UnmarshalCQL(info gocql.TypeInfo, data []byte) e
return nil

default:
vptr := reflect.New(reflect.TypeOf(info.New()))
val, err := info.NewWithError()
if err != nil {
return fmt.Errorf("cannot create new instance of %s: %w", info, err)
}
vptr := reflect.New(reflect.TypeOf(val))
if err := gocql.Unmarshal(info, data, vptr.Interface()); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ require (
golang.org/x/sync v0.8.0
)

replace github.com/gocql/gocql => github.com/scylladb/gocql v1.7.3
replace github.com/gocql/gocql => github.com/scylladb/gocql v1.14.4
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/scylladb/gocql v1.7.3 h1:tCZ44eA4SDC69SHgp1XUcEdWcXi5CQb+iaMOrpncwvI=
github.com/scylladb/gocql v1.7.3/go.mod h1:TA7opQwU+6t8LmGZr/oyudP4QhVj3ucqbtZ73Xu4ghY=
github.com/scylladb/gocql v1.14.4 h1:MhevwCfyAraQ6RvZYFO3pF4Lt0YhvQlfg8Eo2HEqVQA=
github.com/scylladb/gocql v1.14.4/go.mod h1:ZLEJ0EVE5JhmtxIW2stgHq/v1P4fWap0qyyXSKyV8K0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/net v0.0.0-20220526153639-5463443f8c37 h1:lUkvobShwKsOesNfWWlCS5q7fnbG1MEliIzwu886fn8=
golang.org/x/net v0.0.0-20220526153639-5463443f8c37/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a h1:WXEvlFVvvGxCJLG6REjsT03iWnKLEWinaScsxF2Vm2o=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down

0 comments on commit 151802c

Please sign in to comment.