columntypes

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package columntypes implements functions for converting Vitess/MySQL column types to appropriate Go types.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFieldsValuesLenMissmatch occurs when []*query.Field's and []sqltypes.Value's lengths are not equal.
	ErrFieldsValuesLenMissmatch = errors.New("fields and values length missmatch")
	// ErrValueIsNotAString occurs when trying to convert any to string but it fails.
	ErrValueIsNotAString = errors.New("value is not a string")
)
View Source
var ErrInvalidTime = errors.New("invalid MySQL time string")

ErrInvalidTime is returned when we fail to parse a datetime string from MySQL. This should never happen unless things are seriously messed up.

Functions

func ConvertStructureData

func ConvertStructureData(columnTypes map[string]string, data sdk.StructuredData) (sdk.StructuredData, error)

ConvertStructureData converts an sdk.StructureData values to a proper database types. For now it's just converts TIMESTAMP, DATETIME, DATE and TIME values.

func GetColumnTypes

func GetColumnTypes(ctx context.Context, querier Querier, tableName string) (map[string]string, error)

GetColumnTypes returns a map containing all table's columns and their database types.

func TransformValuesToNative

func TransformValuesToNative(fields []*query.Field, values []sqltypes.Value) (map[string]any, error)

TransformValuesToNative converts the values of type sqltypes.Value to appropriate Go types, based on the fields parameter. This is necessary because the underlying raw values are just byte slices.

Types

type Querier

type Querier interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}

Querier is a database querier interface needed for the GetColumnTypes function.

Jump to

Keyboard shortcuts

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