ydb-platform / ydb-go-sdk

Pure Go native and database/sql driver for YDB
https://ydb.tech
Apache License 2.0
136 stars 71 forks source link

Implement struct scanner #1076

Closed asmyasnikov closed 6 months ago

asmyasnikov commented 6 months ago

https://github.com/ydb-platform/ydb-go-sdk/blob/master/internal/query/scanner_struct.go#L20

flymedllva commented 6 months ago

How do I scan to optional values?

migration: name Text

StructScan result:

It would still be cool to support scanning in aliases to types, for example in generating enum from protobuf type TestEnum int32and JSON types in Go structure

asmyasnikov commented 6 months ago

How do I scan to optional values?

migration: name Text

StructScan result:

  • cannot cast 'Test' (type 'Utf8') to '**string' destination
  • cannot cast 'Test' (type 'Utf8') to '*sql.NullString' destination (maybe support https://github.com/guregu/null)

It would still be cool to support scanning in aliases to types, for example in generating enum from protobuf type TestEnum int32and JSON types in Go structure

you can define a pointer to type such as

var v *string
err := row.Scan(&v)
flymedllva commented 6 months ago

How do I scan to optional values? migration: name Text StructScan result:

  • cannot cast 'Test' (type 'Utf8') to '**string' destination
  • cannot cast 'Test' (type 'Utf8') to '*sql.NullString' destination (maybe support https://github.com/guregu/null)

It would still be cool to support scanning in aliases to types, for example in generating enum from protobuf type TestEnum int32and JSON types in Go structure

you can define a pointer to type such as

var v *string
err := row.Scan(&v)

The question was about StructScan, it doesn't work like that with it.