github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/table/result/result.go (about) 1 package result 2 3 import ( 4 "context" 5 6 "github.com/ydb-platform/ydb-go-sdk/v3/table/result/indexed" 7 "github.com/ydb-platform/ydb-go-sdk/v3/table/result/named" 8 "github.com/ydb-platform/ydb-go-sdk/v3/table/stats" 9 ) 10 11 // BaseResult is a result of a query. 12 // 13 // Use NextResultSet(), NextRow() and Scan() to advance through the result sets, 14 // its rows and row's items. 15 // 16 // res, err := s.Execute(ctx, txc, "SELECT ...") 17 // defer res.Close() 18 // for res.NextResultSet(ctx) { 19 // for res.NextRow() { 20 // var id int64 21 // var name *string //optional value 22 // res.Scan(&id,&name) 23 // } 24 // } 25 // if err := res.err() { // get any error encountered during iteration 26 // // handle error 27 // } 28 // 29 // If current value under scan 30 // is not requested types, then res.err() become non-nil. 31 // After that, NextResultSet(), NextRow() will return false. 32 type BaseResult interface { 33 // HasNextResultSet reports whether result set may be advanced. 34 // It may be useful to call HasNextResultSet() instead of NextResultSet() to look ahead 35 // without advancing the result set. 36 // Note that it does not work with sets from stream. 37 HasNextResultSet() bool 38 39 // NextResultSet selects next result set in the result. 40 // columns - names of columns in the resultSet that will be scanned 41 // It returns false if there are no more result sets. 42 // Stream sets are supported. 43 // After iterate over result sets should be checked Err() 44 NextResultSet(ctx context.Context, columns ...string) bool 45 46 // NextResultSetErr selects next result set in the result. 47 // columns - names of columns in the result set that will be scanned 48 // It returns: 49 // - nil if select next result set successful 50 // - io.EOF if no result sets 51 // - some error if an error has occurred 52 // NextResultSetErr func equal to sequential calls HasNextResultSet() and Err() after 53 NextResultSetErr(ctx context.Context, columns ...string) error 54 55 // CurrentResultSet get current result set to use ColumnCount(), RowCount() and other methods 56 CurrentResultSet() Set 57 58 // HasNextRow reports whether result row may be advanced. 59 // It may be useful to call HasNextRow() instead of NextRow() to look ahead 60 // without advancing the result rows. 61 HasNextRow() bool 62 63 // NextRow selects next row in the current result set. 64 // It returns false if there are no more rows in the result set. 65 NextRow() bool 66 67 // ScanWithDefaults scan with default types values. 68 // Nil values applied as default value types 69 // Input params - pointers to types. 70 // If some value implements ydb.table.types.Scanner then will be called 71 // value.(ydb.table.types.Scanner).UnmarshalYDB(raw) where raw may be null. 72 // In this case client-side implementation UnmarshalYDB must check raw.IsNull() and 73 // applied default value or nothing to do 74 ScanWithDefaults(values ...indexed.Required) error 75 76 // Scan values. 77 // Input params - pointers to types: 78 // bool 79 // int8 80 // uint8 81 // int16 82 // uint16 83 // int32 84 // uint32 85 // int64 86 // uint64 87 // float32 88 // float64 89 // []byte 90 // [16]byte 91 // string 92 // time.Time 93 // time.Duration 94 // ydb.valueType 95 // For custom types implement sql.Scanner or json.Unmarshaler interface. 96 // For optional types use double pointer construction. 97 // For unknown types use interface types. 98 // Supported scanning byte arrays of various length. 99 // For complex yql types: Dict, List, Tuple and own specific scanning logic 100 // implement ydb.table.types.Scanner with UnmarshalYDB method 101 // See examples for more detailed information. 102 // Output param - Scanner error 103 Scan(values ...indexed.RequiredOrOptional) error 104 105 // ScanNamed scans row with column names defined in namedValues 106 ScanNamed(namedValues ...named.Value) error 107 108 // Stats returns query execution QueryStats. 109 // 110 // If query result have no stats - returns nil 111 Stats() (s stats.QueryStats) 112 113 // Err return scanner error 114 // To handle errors, do not need to check after scanning each row 115 // It is enough to check after reading all Set 116 Err() error 117 118 // Close closes the Result, preventing further iteration. 119 Close() error 120 } 121 122 type Result interface { 123 BaseResult 124 125 // ResultSetCount returns number of result sets. 126 // Note that it does not work if r is the BaseResult of streaming operation. 127 ResultSetCount() int 128 } 129 130 type StreamResult interface { 131 BaseResult 132 }