|
| 1 | +package scanner |
| 2 | + |
| 3 | +import ( |
| 4 | + "io" |
| 5 | + "time" |
| 6 | + |
| 7 | + "github.com/ydb-platform/ydb-go-sdk/v3/internal/decimal" |
| 8 | + "github.com/ydb-platform/ydb-go-sdk/v3/internal/types" |
| 9 | + "github.com/ydb-platform/ydb-go-sdk/v3/internal/value" |
| 10 | +) |
| 11 | + |
| 12 | +// RawValue scanning non-primitive yql types or for own implementation scanner native API |
| 13 | +type RawValue interface { |
| 14 | + Path() string |
| 15 | + WritePathTo(w io.Writer) (n int64, err error) |
| 16 | + Type() types.Type |
| 17 | + Bool() (v bool) |
| 18 | + Int8() (v int8) |
| 19 | + Uint8() (v uint8) |
| 20 | + Int16() (v int16) |
| 21 | + Uint16() (v uint16) |
| 22 | + Int32() (v int32) |
| 23 | + Uint32() (v uint32) |
| 24 | + Int64() (v int64) |
| 25 | + Uint64() (v uint64) |
| 26 | + Float() (v float32) |
| 27 | + Double() (v float64) |
| 28 | + Date() (v time.Time) |
| 29 | + Datetime() (v time.Time) |
| 30 | + Timestamp() (v time.Time) |
| 31 | + Interval() (v time.Duration) |
| 32 | + TzDate() (v time.Time) |
| 33 | + TzDatetime() (v time.Time) |
| 34 | + TzTimestamp() (v time.Time) |
| 35 | + String() (v []byte) |
| 36 | + UTF8() (v string) |
| 37 | + YSON() (v []byte) |
| 38 | + JSON() (v []byte) |
| 39 | + UUID() (v [16]byte) |
| 40 | + JSONDocument() (v []byte) |
| 41 | + DyNumber() (v string) |
| 42 | + Value() value.Value |
| 43 | + |
| 44 | + // Any returns any primitive or optional value. |
| 45 | + // Currently, it may return one of these types: |
| 46 | + // |
| 47 | + // bool |
| 48 | + // int8 |
| 49 | + // uint8 |
| 50 | + // int16 |
| 51 | + // uint16 |
| 52 | + // int32 |
| 53 | + // uint32 |
| 54 | + // int64 |
| 55 | + // uint64 |
| 56 | + // float32 |
| 57 | + // float64 |
| 58 | + // []byte |
| 59 | + // string |
| 60 | + // [16]byte |
| 61 | + // |
| 62 | + Any() interface{} |
| 63 | + |
| 64 | + // Unwrap unwraps current item under scan interpreting it as Optional<Type> types. |
| 65 | + Unwrap() |
| 66 | + AssertType(t types.Type) bool |
| 67 | + IsNull() bool |
| 68 | + IsOptional() bool |
| 69 | + |
| 70 | + // ListIn interprets current item under scan as a ydb's list. |
| 71 | + // It returns the size of the nested items. |
| 72 | + // If current item under scan is not a list types, it returns -1. |
| 73 | + ListIn() (size int) |
| 74 | + |
| 75 | + // ListItem selects current item i-th element as an item to scan. |
| 76 | + // ListIn() must be called before. |
| 77 | + ListItem(i int) |
| 78 | + |
| 79 | + // ListOut leaves list entered before by ListIn() call. |
| 80 | + ListOut() |
| 81 | + |
| 82 | + // TupleIn interprets current item under scan as a ydb's tuple. |
| 83 | + // It returns the size of the nested items. |
| 84 | + TupleIn() (size int) |
| 85 | + |
| 86 | + // TupleItem selects current item i-th element as an item to scan. |
| 87 | + // Note that TupleIn() must be called before. |
| 88 | + // It panics if it is out of bounds. |
| 89 | + TupleItem(i int) |
| 90 | + |
| 91 | + // TupleOut leaves tuple entered before by TupleIn() call. |
| 92 | + TupleOut() |
| 93 | + |
| 94 | + // StructIn interprets current item under scan as a ydb's struct. |
| 95 | + // It returns the size of the nested items – the struct fields values. |
| 96 | + // If there is no current item under scan it returns -1. |
| 97 | + StructIn() (size int) |
| 98 | + |
| 99 | + // StructField selects current item i-th field value as an item to scan. |
| 100 | + // Note that StructIn() must be called before. |
| 101 | + // It panics if i is out of bounds. |
| 102 | + StructField(i int) (name string) |
| 103 | + |
| 104 | + // StructOut leaves struct entered before by StructIn() call. |
| 105 | + StructOut() |
| 106 | + |
| 107 | + // DictIn interprets current item under scan as a ydb's dict. |
| 108 | + // It returns the size of the nested items pairs. |
| 109 | + // If there is no current item under scan it returns -1. |
| 110 | + DictIn() (size int) |
| 111 | + |
| 112 | + // DictKey selects current item i-th pair key as an item to scan. |
| 113 | + // Note that DictIn() must be called before. |
| 114 | + // It panics if i is out of bounds. |
| 115 | + DictKey(i int) |
| 116 | + |
| 117 | + // DictPayload selects current item i-th pair value as an item to scan. |
| 118 | + // Note that DictIn() must be called before. |
| 119 | + // It panics if i is out of bounds. |
| 120 | + DictPayload(i int) |
| 121 | + |
| 122 | + // DictOut leaves dict entered before by DictIn() call. |
| 123 | + DictOut() |
| 124 | + |
| 125 | + // Variant unwraps current item under scan interpreting it as Variant<Type> types. |
| 126 | + // It returns non-empty name of a field that is filled for struct-based |
| 127 | + // variant. |
| 128 | + // It always returns an index of filled field of a Type. |
| 129 | + Variant() (name string, index uint32) |
| 130 | + |
| 131 | + // Decimal returns decimal value represented by big-endian 128 bit signed integer. |
| 132 | + Decimal(t types.Type) (v [16]byte) |
| 133 | + |
| 134 | + // UnwrapDecimal returns decimal value represented by big-endian 128 bit signed |
| 135 | + // integer and its types information. |
| 136 | + UnwrapDecimal() decimal.Decimal |
| 137 | + IsDecimal() bool |
| 138 | + Err() error |
| 139 | +} |
| 140 | + |
| 141 | +// Scanner scanning raw ydb types |
| 142 | +type Scanner interface { |
| 143 | + // UnmarshalYDB must be implemented on client-side for unmarshal raw ydb value. |
| 144 | + UnmarshalYDB(raw RawValue) error |
| 145 | +} |
0 commit comments