columntypes

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValueIsNotAString                = errors.New("value is not a string")
	ErrCannotConvertValueToBytes        = errors.New("cannot convert value to byte slice")
	ErrCannotConvertValueToDecimal      = errors.New("cannot convert value to decimal")
	ErrInvalidDecimalStringPresentation = errors.New("invalid decimal string presentation")
	ErrCannotConvertToInt               = errors.New("cannot convert value to int type")
	ErrInvalidTimeLayout                = errors.New("invalid time layout")
)

Functions

func ConvertStructuredData

func ConvertStructuredData(
	_ context.Context,
	columnTypes map[string]string,
	data sdk.StructuredData,
) (sdk.StructuredData, error)

ConvertStructuredData converts a sdk.StructureData values to a proper database types.

func TransformRow

func TransformRow(_ context.Context, row map[string]any, columnTypes map[string]string) (map[string]any, error)

TransformRow converts row map values to appropriate Go types, based on the columnTypes.

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.

type TableInfo

type TableInfo struct {
	// ColumnTypes - column name with column type.
	ColumnTypes map[string]string
	// PrimaryKeys - primary keys column names.
	PrimaryKeys []string
	// ColumnLengths - column name with length.
	ColumnLengths map[string]int
	// ColumnScales - column name with scale.
	ColumnScales map[string]*int
}

TableInfo - information about colum types, primary keys from table.

func GetTableInfo

func GetTableInfo(ctx context.Context, querier Querier, tableName string) (TableInfo, error)

GetTableInfo returns a map containing all table's columns and their database types and returns primary columns names.

func (TableInfo) GetColumnQueryPart

func (t TableInfo) GetColumnQueryPart() string

GetColumnQueryPart prepare query part about creation column for tracking table. For example: NAME VARCHAR(40), AGE INT, ADDRESS VARCHAR(120).

Jump to

Keyboard shortcuts

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