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