package sugar
import "github.com/ydb-platform/ydb-go-sdk/v3/sugar"
Example (UnmarshallResultSet)¶
Code:
{ ctx := context.TODO() db, err := ydb.Open(ctx, "grpc://localhost:2136/local") if err != nil { panic(err) } defer db.Close(ctx) // cleanup resources type myStruct struct { ID int32 `sql:"id"` Str string `sql:"myStr"` } rows, err := db.Query().ReadResultSet(ctx, ` SELECT 42 as id, "myStr42" as myStr UNION SELECT 43 as id, "myStr43" as myStr ORDER BY id `) if err != nil { panic(err) } many, err := sugar.UnmarshallResultSet[myStruct](rows) if err != nil { panic(err) } fmt.Print("many = [") for i, s := range many { if i > 0 { fmt.Print(",") } fmt.Printf("\n\t%+v", s) } fmt.Println("\n]") // many = [ // &{ID:42 Str:myStr42}, // &{ID:43 Str:myStr43} //] }
Example (UnmarshallRow)¶
Code:
{ ctx := context.TODO() db, err := ydb.Open(ctx, "grpc://localhost:2136/local") if err != nil { panic(err) } defer db.Close(ctx) // cleanup resources type myStruct struct { ID int32 `sql:"id"` Str string `sql:"myStr"` } row, err := db.Query().ReadRow(ctx, `SELECT 42 as id, "my string" as myStr`) if err != nil { panic(err) } one, err := sugar.UnmarshallRow[*myStruct](row) if err != nil { panic(err) } fmt.Printf("one = %+v\n", one) // one = &{ID:42 Str:my string} }
Index ¶
- func DSN(endpoint, database string, secure bool) (s string)
- func GenerateDeclareSection[T constraint](parameters T) (string, error)
- func IsColumnTableExists(ctx context.Context, c scheme.Client, absTablePath string) (exists bool, _ error)
- func IsDirectoryExists(ctx context.Context, c scheme.Client, absTablePath string) (exists bool, _ error)
- func IsEntryExists(ctx context.Context, c scheme.Client, absPath string, entryTypes ...scheme.EntryType) ( exists bool, _ error, )
- func IsTableExists(ctx context.Context, c scheme.Client, absTablePath string) (exists bool, _ error)
- func LoadCertificatesFromFile(caFile string) ([]*x509.Certificate, error)
- func LoadCertificatesFromPem(bytes []byte) (certs []*x509.Certificate)
- func MakeRecursive(ctx context.Context, db dbForMakeRecursive, pathToCreate string) error
- func RemoveRecursive(ctx context.Context, db dbFoRemoveRecursive, pathToRemove string) error
- func Result(r query.Result) *result
- func StackRecord(depth int) string
- func ToYdbParam(param sql.NamedArg) (*params.Parameter, error)
- func UnmarshallResultSet[T any](resultSet query.ResultSet) (values []*T, _ error)
- func UnmarshallRow[T any](row query.Row) (*T, error)
Examples ¶
Functions ¶
func DSN ¶
DSN makes connection string (data source name) by endpoint, database and secure
func GenerateDeclareSection ¶
GenerateDeclareSection generates DECLARE section text in YQL query by params
Deprecated: use testutil.QueryBind(ydb.WithAutoDeclare()) helper. In YDB since version 24.1 declare sections not requires. Will be removed after Oct 2024. Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
func IsColumnTableExists ¶
func IsColumnTableExists(ctx context.Context, c scheme.Client, absTablePath string) (exists bool, _ error)
func IsDirectoryExists ¶
func IsDirectoryExists(ctx context.Context, c scheme.Client, absTablePath string) (exists bool, _ error)
func IsEntryExists ¶
func IsEntryExists(ctx context.Context, c scheme.Client, absPath string, entryTypes ...scheme.EntryType) ( exists bool, _ error, )
func IsTableExists ¶
func IsTableExists(ctx context.Context, c scheme.Client, absTablePath string) (exists bool, _ error)
func LoadCertificatesFromFile ¶
func LoadCertificatesFromFile(caFile string) ([]*x509.Certificate, error)
LoadCertificatesFromFile read and parse caFile and returns certificates
func LoadCertificatesFromPem ¶
func LoadCertificatesFromPem(bytes []byte) (certs []*x509.Certificate)
LoadCertificatesFromPem parse bytes and returns certificates
func MakeRecursive ¶
MakeRecursive creates path inside database pathToCreate is a database root relative path MakeRecursive method equal bash command `mkdir -p ~/path/to/create` where `~` - is a root of database
func RemoveRecursive ¶
RemoveRecursive remove selected directory or table names in database. pathToRemove is a database root relative path All database entities in prefix path will remove if names list is empty. Empty prefix means than use root of database. RemoveRecursive method equal bash command `rm -rf ~/path/to/remove` where `~` - is a root of database
func Result ¶
Result converts query.Result to iterable result for compatibility with table/result.Result usage
Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental
func StackRecord ¶
func ToYdbParam ¶
ToYdbParam converts
Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals
func UnmarshallResultSet ¶
UnmarshallResultSet returns slice of typed objects from given query.ResultSet
Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental
func UnmarshallRow ¶
UnmarshallRow returns typed object from query.Row
Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental
Source Files ¶
certificates.go check_exists.go dsn.go params.go path.go query.go result.go stack.go
- Version
- v3.70.0
- Published
- Jun 4, 2024
- Platform
- linux/amd64
- Imports
- 26 packages
- Last checked
- 29 minutes ago –
Tools for package owners.