sugar

package
v3.78.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2024 License: Apache-2.0 Imports: 26 Imported by: 19

Documentation

Overview

Example (UnmarshallResultSet)
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().QueryResultSet(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}
//]
Output:

Example (UnmarshallRow)
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().QueryRow(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}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DSN added in v3.21.0

func DSN(endpoint, database string, secure bool) (s string)

DSN makes connection string (data source name) by endpoint, database and secure

func GenerateDeclareSection deprecated added in v3.28.0

func GenerateDeclareSection[T constraint](parameters T) (string, error)

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 added in v3.48.1

func IsColumnTableExists(ctx context.Context, c scheme.Client, absTablePath string) (exists bool, _ error)

func IsDirectoryExists added in v3.42.7

func IsDirectoryExists(ctx context.Context, c scheme.Client, absTablePath string) (exists bool, _ error)

func IsEntryExists added in v3.48.1

func IsEntryExists(ctx context.Context, c scheme.Client, absPath string, entryTypes ...scheme.EntryType) (
	exists bool, _ error,
)

func IsTableExists added in v3.40.0

func IsTableExists(ctx context.Context, c scheme.Client, absTablePath string) (exists bool, _ error)

func LoadCertificatesFromFile added in v3.23.0

func LoadCertificatesFromFile(caFile string) ([]*x509.Certificate, error)

LoadCertificatesFromFile read and parse caFile and returns certificates

func LoadCertificatesFromPem added in v3.23.0

func LoadCertificatesFromPem(bytes []byte) (certs []*x509.Certificate)

LoadCertificatesFromPem parse bytes and returns certificates

func MakeRecursive added in v3.5.2

func MakeRecursive(ctx context.Context, db dbForMakeRecursive, pathToCreate string) error

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 added in v3.5.2

func RemoveRecursive(ctx context.Context, db dbFoRemoveRecursive, pathToRemove string) error

RemoveRecursive removes selected directory or table names in the database. pathToRemove is a database root relative path. All database entities in the prefix path will be removed if the names list is empty. An empty prefix means using the root of the database. RemoveRecursive method is equivalent to the bash command `rm -rf ~/path/to/remove` where `~` is the root of the database.

func Result added in v3.57.0

func Result(r query.Result) *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 added in v3.48.7

func StackRecord(depth int) string

func ToYdbParam added in v3.38.0

func ToYdbParam(param sql.NamedArg) (*params.Parameter, error)

ToYdbParam converts

Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals

func UnmarshallResultSet added in v3.69.0

func UnmarshallResultSet[T any](resultSet query.ResultSet) (values []*T, _ error)

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 added in v3.69.0

func UnmarshallRow[T any](row query.Row) (*T, error)

UnmarshallRow returns typed object from query.Row

Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL