toolkit

package
v0.0.0-...-2fb5fa7 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2025 License: Apache-2.0 Imports: 39 Imported by: 2

Documentation

Index

Constants

View Source
const (
	FkConstraintType           = "ForeignKey"
	CheckConstraintType        = "Check"
	NotNullConstraintType      = "NotNull"
	PkConstraintType           = "PrimaryKey"
	PkConstraintReferencesType = "PrimaryKeyReferences"
	UniqueConstraintType       = "Unique"
	LengthConstraintType       = "Length"
	ExclusionConstraintType    = "Exclusion"
	TriggerConstraintType      = "TriggerConstraint"
)
View Source
const (
	CsvAttributesDirectNumeratingFormatName = "direct"
	CsvAttributesConfigNumeratingFormatName = "config"
)
View Source
const (
	TableMovedToAnotherSchemaDiffEvent = "TableMovedToAnotherSchema"
	TableRenamedDiffEvent              = "TableRenamed"
	TableCreatedDiffEvent              = "TableCreated"
	ColumnCreatedDiffEvent             = "ColumnCreated"
	ColumnRenamedDiffEvent             = "ColumnRenamed"
	ColumnTypeChangedDiffEvent         = "ColumnTypeChanged"
)
View Source
const (
	JsonModeName = "json"
	CsvModeName  = "csv"
	TextModeName = "text"
)
View Source
const (
	JsonAttributesIndexesFormatName = "indexes"
	JsonAttributesNamesFormatName   = "names"
	JsonBytesDataFormatName         = "bytes"
	JsonTextDataFormatName          = "text"
)
View Source
const (
	MPassword   string = "password"
	MName       string = "name"
	MAddress    string = "addr"
	MEmail      string = "email"
	MMobile     string = "mobile"
	MTelephone  string = "tel"
	MID         string = "id"
	MCreditCard string = "credit_card"
	MURL        string = "url"
	MDefault    string = "default"
)
View Source
const (
	SecUnixUnixName   = "sec"
	MilliUnixUnixName = "milli"
	MicroUnixUnixName = "micro"
	NanoUnixUnixName  = "nano"
)
View Source
const (
	ErrorValidationSeverity   = "error"
	WarningValidationSeverity = "warning"
	InfoValidationSeverity    = "info"
	DebugValidationSeverity   = "debug"
)
View Source
const WithoutMaxLength = -1

Variables

View Source
var (
	UnixNanoToDate         = unixLikeToTimeLikeFuncMaker("date", NanoUnixUnixName)
	UnixMicroToDate        = unixLikeToTimeLikeFuncMaker("date", MicroUnixUnixName)
	UnixMilliToDate        = unixLikeToTimeLikeFuncMaker("date", MilliUnixUnixName)
	UnixSecToDate          = unixLikeToTimeLikeFuncMaker("date", SecUnixUnixName)
	UnixNanoToTimestamp    = unixLikeToTimeLikeFuncMaker("timestamp", NanoUnixUnixName)
	UnixMicroToTimestamp   = unixLikeToTimeLikeFuncMaker("timestamp", MicroUnixUnixName)
	UnixMilliToTimestamp   = unixLikeToTimeLikeFuncMaker("timestamp", MilliUnixUnixName)
	UnixSecToTimestamp     = unixLikeToTimeLikeFuncMaker("timestamp", SecUnixUnixName)
	UnixNanoToTimestampTz  = unixLikeToTimeLikeFuncMaker("timestamptz", NanoUnixUnixName)
	UnixMicroToTimestampTz = unixLikeToTimeLikeFuncMaker("timestamptz", MicroUnixUnixName)
	UnixMilliToTimestampTz = unixLikeToTimeLikeFuncMaker("timestamptz", MilliUnixUnixName)
	UnixSecToTimestampTz   = unixLikeToTimeLikeFuncMaker("timestamptz", SecUnixUnixName)

	DateToUnixNano         = timeLikeToUnixLikeFuncMaker("date", NanoUnixUnixName)
	DateToUnixMicro        = timeLikeToUnixLikeFuncMaker("date", MicroUnixUnixName)
	DateToUnixMilli        = timeLikeToUnixLikeFuncMaker("date", MilliUnixUnixName)
	DateToUnixSec          = timeLikeToUnixLikeFuncMaker("date", SecUnixUnixName)
	TimestampToUnixNano    = timeLikeToUnixLikeFuncMaker("timestamp", NanoUnixUnixName)
	TimestampToUnixMicro   = timeLikeToUnixLikeFuncMaker("timestamp", MicroUnixUnixName)
	TimestampToUnixMilli   = timeLikeToUnixLikeFuncMaker("timestamp", MilliUnixUnixName)
	TimestampToUnixSec     = timeLikeToUnixLikeFuncMaker("timestamp", SecUnixUnixName)
	TimestampTzToUnixNano  = timeLikeToUnixLikeFuncMaker("timestamptz", NanoUnixUnixName)
	TimestampTzToUnixMicro = timeLikeToUnixLikeFuncMaker("timestamptz", MicroUnixUnixName)
	TimestampTzToUnixMilli = timeLikeToUnixLikeFuncMaker("timestamptz", MilliUnixUnixName)
	TimestampTzToUnixSec   = timeLikeToUnixLikeFuncMaker("timestamptz", SecUnixUnixName)
)
View Source
var CastFunctionsMap = map[string]*TypeCastDefinition{
	"UnixNanoToDate": {
		Cast:        UnixNanoToDate,
		InputTypes:  []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
		OutputTypes: []string{"date"},
	},
	"UnixMicroToDate": {
		Cast:        UnixMicroToDate,
		InputTypes:  []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
		OutputTypes: []string{"date"},
	},
	"UnixMilliToDate": {
		Cast:        UnixMilliToDate,
		InputTypes:  []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
		OutputTypes: []string{"date"},
	},
	"UnixSecToDate": {
		Cast:        UnixSecToDate,
		InputTypes:  []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
		OutputTypes: []string{"date"},
	},

	"UnixNanoToTimestamp": {
		Cast:        UnixNanoToTimestamp,
		InputTypes:  []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
		OutputTypes: []string{"timestamp"},
	},
	"UnixMicroToTimestamp": {
		Cast:        UnixMicroToTimestamp,
		InputTypes:  []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
		OutputTypes: []string{"timestamp"},
	},
	"UnixMilliToTimestamp": {
		Cast:        UnixMilliToTimestamp,
		InputTypes:  []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
		OutputTypes: []string{"timestamp"},
	},
	"UnixSecToTimestamp": {
		Cast:        UnixSecToTimestamp,
		InputTypes:  []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
		OutputTypes: []string{"timestamp"},
	},

	"UnixNanoToTimestampTz": {
		Cast:        UnixNanoToTimestampTz,
		InputTypes:  []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
		OutputTypes: []string{"timestamptz"},
	},
	"UnixMicroToTimestampTz": {
		Cast:        UnixMicroToTimestampTz,
		InputTypes:  []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
		OutputTypes: []string{"timestamptz"},
	},
	"UnixMilliToTimestampTz": {
		Cast:        UnixMilliToTimestampTz,
		InputTypes:  []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
		OutputTypes: []string{"timestamptz"},
	},
	"UnixSecToTimestampTz": {
		Cast:        UnixSecToTimestampTz,
		InputTypes:  []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
		OutputTypes: []string{"timestamptz"},
	},

	"DateToUnixNano": {
		Cast:        DateToUnixNano,
		InputTypes:  []string{"date"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
	},
	"DateToUnixMicro": {
		Cast:        DateToUnixMicro,
		InputTypes:  []string{"date"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
	},
	"DateToUnixMilli": {
		Cast:        DateToUnixMilli,
		InputTypes:  []string{"date"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
	},
	"DateToUnixSec": {
		Cast:        DateToUnixSec,
		InputTypes:  []string{"date"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
	},
	"TimestampToUnixNano": {
		Cast:        TimestampToUnixNano,
		InputTypes:  []string{"timestamp"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
	},
	"TimestampToUnixMicro": {
		Cast:        TimestampToUnixMicro,
		InputTypes:  []string{"timestamp"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
	},
	"TimestampToUnixMilli": {
		Cast:        TimestampToUnixMilli,
		InputTypes:  []string{"timestamp"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
	},
	"TimestampToUnixSec": {
		Cast:        TimestampToUnixSec,
		InputTypes:  []string{"timestamp"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
	},
	"TimestampTzToUnixNano": {
		Cast:        TimestampTzToUnixNano,
		InputTypes:  []string{"date"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
	},
	"TimestampTzToUnixMicro": {
		Cast:        TimestampTzToUnixMicro,
		InputTypes:  []string{"timestamptz"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
	},
	"TimestampTzToUnixMilli": {
		Cast:        TimestampTzToUnixMilli,
		InputTypes:  []string{"timestamptz"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
	},
	"TimestampTzToUnixSec": {
		Cast:        TimestampTzToUnixSec,
		InputTypes:  []string{"timestamptz"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
	},

	"FloatToInt": {
		Cast:        CastFloatToInt,
		InputTypes:  []string{"numeric", "float4", "float8"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric"},
	},
	"IntToFloat": {
		Cast:        CastIntToFloat,
		InputTypes:  []string{"int2", "int4", "int8", "numeric"},
		OutputTypes: []string{"numeric", "float4", "float8"},
	},
	"IntToBool": {
		Cast:        IntToBool,
		InputTypes:  []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
		OutputTypes: []string{"bool"},
	},
	"BoolToInt": {
		Cast:        BoolToInt,
		InputTypes:  []string{"bool"},
		OutputTypes: []string{"int2", "int4", "int8", "numeric", "float4", "float8"},
	},
}
View Source
var DefaultRowDriverParams = DriverParams{
	Name:                 JsonModeName,
	JsonDataFormat:       JsonBytesDataFormatName,
	JsonAttributesFormat: JsonAttributesIndexesFormatName,
	CsvAttributesFormat:  CsvAttributesDirectNumeratingFormatName,
}
View Source
var DiffEventMsgs = map[string]string{
	TableMovedToAnotherSchemaDiffEvent: "Table moved to another schema",
	TableRenamedDiffEvent:              "Table renamed",
	TableCreatedDiffEvent:              "Table created",
	ColumnCreatedDiffEvent:             "Column created",
	ColumnRenamedDiffEvent:             "Column renamed",
	ColumnTypeChangedDiffEvent:         "Column type changed",
}
View Source
var (
	KindOfType = map[rune]string{
		'b': "Base",
		'c': "Composite",
		'd': "Domain",
		'e': "Enum",
		'p': "PreSudo",
		'r': "Range",
		'm': "Multirange",
	}
)

Functions

func AreTypesHaveEqualOrHaveEqualBaseTypes

func AreTypesHaveEqualOrHaveEqualBaseTypes(driver *Driver, customTypes []*Type, a string, b string) bool

func BoolToInt

func BoolToInt(driver *Driver, input []byte) (output []byte, err error)

func CastFloatToInt

func CastFloatToInt(driver *Driver, input []byte) (output []byte, err error)

func CastIntToFloat

func CastIntToFloat(driver *Driver, input []byte) (output []byte, err error)

func DefaultDatabaseTypeUnmarshaler

func DefaultDatabaseTypeUnmarshaler(driver *Driver, typeName string, v ParamsValue) (any, error)

func FuncMap

func FuncMap() template.FuncMap

func GetAffectedAndTransferringColumns

func GetAffectedAndTransferringColumns(parameters map[string]Parameterizer, driver *Driver) (
	affectedColumnsIdx []*Column, transferringColumnsIdx []*Column, err error,
)

func GetCanonicalTypeName

func GetCanonicalTypeName(driver *Driver, typeName string, typeOid uint32) string

func GetDriverAndRecord

func GetDriverAndRecord(columnValues map[string]*RawValue) (*Driver, *Record)

GetDriverAndRecord - return adhoc table for testing TODO: You should generate table definition dynamically using faker as well as table tuples

func IntToBool

func IntToBool(driver *Driver, input []byte) (output []byte, err error)

func IsTypeAllowed

func IsTypeAllowed(
	driver *Driver, allowedTypes []string, typeName string, checkInherited bool,
) bool

func IsTypeAllowedWithTypeMap

func IsTypeAllowedWithTypeMap(
	driver *Driver, allowedTypes []string, typeName string, typeOid Oid, checkInherited bool,
) bool

func IsTypeCustom

func IsTypeCustom(customTypes []*Type, typeOid Oid) bool

func NewDriver

func NewDriver(table *Table, customTypes []*Type) (*Driver, ValidationWarnings, error)

func NewTypeCaster

func NewTypeCaster(driver *Driver, inputType, outputType, castFunction string) (*TypeCaster, ValidationWarnings, error)

func NewWhenCond

func NewWhenCond(when string, driver *Driver, meta map[string]any) (*WhenCond, ValidationWarnings)

NewWhenCond - creates a new WhenCond object. It compiles the when condition and returns the compiled program and the record context with the functions for the columns. The functions represent the column names and return the column values. If the when condition is empty, the WhenCond object will always return true.

func NoiseDateV2

func NoiseDateV2(r *rand.Rand, ratio time.Duration, t *time.Time) *time.Time

func NoiseFloat

func NoiseFloat(r *rand.Rand, ratio float64, value float64, precision int) float64

func NoiseInt

func NoiseInt(r *rand.Rand, ratio float64, value int64) int64

func PrintValidationWarnings

func PrintValidationWarnings(warns ValidationWarnings, resolvedWarnings []string, printAll bool) error

func RandomBool

func RandomBool(r *rand.Rand) bool

func RandomDate

func RandomDate(r *rand.Rand, min, max *time.Time) *time.Time

func RandomFloat

func RandomFloat(r *rand.Rand, min, max float64, precision int) float64

func RandomInt

func RandomInt(r *rand.Rand, min, max int64) int64

func RandomString

func RandomString(randGen *rand.Rand, minLength, maxLength int64, symbols []rune, buf []rune) string

func Round

func Round(precision int, num float64) float64

func ScanPointer

func ScanPointer(src, dest any) error

func TruncateDate

func TruncateDate(part *string, t *time.Time) (*time.Time, error)

TruncateDate - truncate date till the provided part of date

func TryRegisterCustomTypes

func TryRegisterCustomTypes(typeMap *pgtype.Map, types []*Type, silent bool)

Types

type AttNum

type AttNum uint32

type Check

func NewCheck

func NewCheck(schema, name, definition string, oid Oid, columns []AttNum) *Check

func (*Check) IsAffected

func (c *Check) IsAffected(column *Column, columnProperties *ColumnProperties) (w ValidationWarnings)

func (*Check) Type

func (c *Check) Type() string

type Cmd

type Cmd struct {
	*cobra.Command
	// contains filtered or unexported fields
}

func NewCmd

func NewCmd(definition *TransformerDefinition) *Cmd

type Column

type Column struct {
	Idx               int    `json:"idx"`
	Name              string `json:"name"`
	TypeName          string `json:"type_name"`
	CanonicalTypeName string `json:"canonical_type_name"`
	TypeOid           Oid    `json:"type_oid"`
	Num               AttNum `json:"num"`
	NotNull           bool   `json:"not_null"`
	// Length - length of the attribute
	Length      int  `json:"length"`
	TypeLength  int  `json:"type_length"`
	IsGenerated bool `json:"is_generated"`
	// OverriddenTypeName - replacement of  original type. For instance override TEXT to INT2
	OverriddenTypeName string `json:"overridden_type_name"`
	OverriddenTypeOid  Oid    `json:"overridden_type_oid"`
	OverriddenTypeSize int    `json:"overridden_type_size"`
}

func (*Column) GetColumnSize

func (c *Column) GetColumnSize() int

func (*Column) GetType

func (c *Column) GetType() (string, Oid)

func (*Column) GetTypeOid

func (c *Column) GetTypeOid() Oid

func (*Column) OverrideType

func (c *Column) OverrideType(name string, oid Oid, size int)

type ColumnProperties

type ColumnProperties struct {
	// Nullable - shows that transformer can produce NULL value for the column. Togather with Affected shows that
	// this parameter may generate null values and write it in this column. It only plays with Affected
	Nullable bool `mapstructure:"nullable" json:"nullable,omitempty"`
	// Unique - shows that transformer guarantee that every transformer call the value will be unique. It only plays
	// with Affected
	Unique bool `mapstructure:"unique" json:"unique,omitempty"`
	// Unique - defines max length of the value. It only plays with Affected. Togather with Affected shows
	// that values will not exceed the length of the column. It only plays with Affected
	MaxLength int `mapstructure:"max_length" json:"max_length,omitempty"`
	// Affected - shows assigned column name will be affected after the transformation
	Affected bool `mapstructure:"affected" json:"affected,omitempty"`
	// AllowedTypes - defines all the allowed column types in textual format. If not assigned (nil) then any
	// of the types is valid
	// TODO: AllowedTypes has a problem if we set int and our column is int2, then it cause an error though
	//		 it is workable case. Decide how to define subtype or type "aliases" references.
	//		 Also it has problem with custom type naming because it has schema name and type name. It might be better
	//		 to describe types with {{ schemaName }}.{{ typeName }}, but then we have to implement types classes
	//		 (such as textual, digits, etc.)
	AllowedTypes []string `mapstructure:"allowed_types" json:"allowed_types,omitempty"`
	// SkipOriginalData - Is transformer require original data or not
	SkipOriginalData bool `mapstructure:"skip_original_data" json:"skip_original_data,omitempty"`
	// TODO: Implement SkipOnNull
	// SkipOnNull - transformation for column with NULL is not expected
	SkipOnNull bool `mapstructure:"skip_on_null" json:"skip_on_null"`
}

ColumnProperties - column-like parameter properties that would help to understand the affection on the consistency

func NewColumnProperties

func NewColumnProperties() *ColumnProperties

func (*ColumnProperties) SetAffected

func (cp *ColumnProperties) SetAffected(v bool) *ColumnProperties

func (*ColumnProperties) SetAllowedColumnTypes

func (cp *ColumnProperties) SetAllowedColumnTypes(v ...string) *ColumnProperties

func (*ColumnProperties) SetMaxLength

func (cp *ColumnProperties) SetMaxLength(v int) *ColumnProperties

func (*ColumnProperties) SetNullable

func (cp *ColumnProperties) SetNullable(v bool) *ColumnProperties

func (*ColumnProperties) SetSkipOnNull

func (cp *ColumnProperties) SetSkipOnNull(v bool) *ColumnProperties

func (*ColumnProperties) SetSkipOriginalData

func (cp *ColumnProperties) SetSkipOriginalData(v bool) *ColumnProperties

func (*ColumnProperties) SetUnique

func (cp *ColumnProperties) SetUnique(v bool) *ColumnProperties

type Constraint

type Constraint interface {
	IsAffected(column *Column, columnProperties *ColumnProperties) (w ValidationWarnings)
	Type() string
}

type CsvApi

type CsvApi struct {
	// contains filtered or unexported fields
}

func NewCsvApi

func NewCsvApi(transferringColumns []*Column, affectedColumns []*Column, driver *Driver, params *DriverParams) *CsvApi

func (*CsvApi) Clean

func (ca *CsvApi) Clean()

func (*CsvApi) Decode

func (ca *CsvApi) Decode(ctx context.Context) (RowDriver, error)

func (*CsvApi) Encode

func (ca *CsvApi) Encode(ctx context.Context, row RowDriver) (err error)

func (*CsvApi) GetRowDriverFromRecord

func (ca *CsvApi) GetRowDriverFromRecord(r *Record) (RowDriver, error)

func (*CsvApi) SetReader

func (ca *CsvApi) SetReader(r io.Reader)

func (*CsvApi) SetRowDriverToRecord

func (ca *CsvApi) SetRowDriverToRecord(rd RowDriver, r *Record) error

func (*CsvApi) SetWriter

func (ca *CsvApi) SetWriter(w io.Writer)

type DatabaseSchema

type DatabaseSchema []*Table

func (DatabaseSchema) Diff

func (ds DatabaseSchema) Diff(current DatabaseSchema) (res []*DiffNode)

type DatabaseTypeUnmarshaler

type DatabaseTypeUnmarshaler func(driver *Driver, typeName string, v ParamsValue) (any, error)

type DefaultConstraintDefinition

type DefaultConstraintDefinition struct {
	// Schema - constraint schema name
	Schema string `json:"schema"`
	// Name - constraint name
	Name string `json:"name"`
	// Oid - Constraint oid in pg_constraint
	Oid Oid `json:"oid"`
	// Columns - columns involved into constraint
	Columns []AttNum `json:"columns,omitempty"`
	// Definition - real textual constraint definition
	Definition string `json:"definition,omitempty"`
}

type DiffNode

type DiffNode struct {
	Event     string            `json:"event,omitempty"`
	Signature map[string]string `json:"signature,omitempty"`
}

type Driver

type Driver struct {
	Table         *Table
	TypeMapPool   []*pgtype.Map
	SharedTypeMap *pgtype.Map
	// ColumnMap - map column name to Column object
	ColumnMap map[string]*Column
	// AttrIdxMap - the number of attribute in tuple
	AttrIdxMap map[string]int
	// CustomTypes - list of custom types used in tables
	CustomTypes []*Type
	// contains filtered or unexported fields
}

Driver - allows you to perform decoding operations from []bytes to go types and go types to bytes encoding operation TODO: Rename it to table Driver

func (*Driver) DecodeValueByColumnIdx

func (d *Driver) DecodeValueByColumnIdx(idx int, src []byte) (any, error)

func (*Driver) DecodeValueByColumnName

func (d *Driver) DecodeValueByColumnName(name string, src []byte) (any, error)

func (*Driver) DecodeValueByTypeName

func (d *Driver) DecodeValueByTypeName(name string, src []byte) (any, error)

func (*Driver) DecodeValueByTypeOid

func (d *Driver) DecodeValueByTypeOid(oid uint32, src []byte) (any, error)

func (*Driver) EncodeValueByColumnIdx

func (d *Driver) EncodeValueByColumnIdx(idx int, src any, buf []byte) ([]byte, error)

func (*Driver) EncodeValueByColumnName

func (d *Driver) EncodeValueByColumnName(name string, src any, buf []byte) ([]byte, error)

func (*Driver) EncodeValueByTypeName

func (d *Driver) EncodeValueByTypeName(name string, src any, buf []byte) ([]byte, error)

func (*Driver) EncodeValueByTypeOid

func (d *Driver) EncodeValueByTypeOid(oid uint32, src any, buf []byte) ([]byte, error)

func (*Driver) GetColumnByName

func (d *Driver) GetColumnByName(name string) (int, *Column, bool)

func (*Driver) GetTypeMap

func (d *Driver) GetTypeMap() *pgtype.Map

func (*Driver) ScanValueByColumnIdx

func (d *Driver) ScanValueByColumnIdx(idx int, src []byte, dest any) error

func (*Driver) ScanValueByColumnName

func (d *Driver) ScanValueByColumnName(name string, src []byte, dest any) error

func (*Driver) ScanValueByTypeName

func (d *Driver) ScanValueByTypeName(name string, src []byte, dest any) error

func (*Driver) ScanValueByTypeOid

func (d *Driver) ScanValueByTypeOid(oid uint32, src []byte, dest any) error

type DriverParams

type DriverParams struct {
	Name                 string `json:"name"`
	JsonDataFormat       string `json:"json_data_format,omitempty"`
	JsonAttributesFormat string `json:"json_attributes_format,omitempty"`
	CsvAttributesFormat  string `json:"csv_attributes_format,omitempty"`
}

func (*DriverParams) Validate

func (dp *DriverParams) Validate() error

Validate - validate driver params and set default values if needed

type DynamicModeProperties

type DynamicModeProperties struct {
	SupportedTypes []string
	Unmarshal      DatabaseTypeUnmarshaler `json:"-"`
}

func NewDynamicModeProperties

func NewDynamicModeProperties() *DynamicModeProperties

func (*DynamicModeProperties) SetCompatibleTypes

func (dmp *DynamicModeProperties) SetCompatibleTypes(compatibleTypes ...string) *DynamicModeProperties

func (*DynamicModeProperties) SetUnmarshaler

func (dmp *DynamicModeProperties) SetUnmarshaler(unmarshaler DatabaseTypeUnmarshaler) *DynamicModeProperties

type DynamicParamValue

type DynamicParamValue struct {
	Column       string      `mapstructure:"column" json:"column,omitempty"`
	CastTo       string      `mapstructure:"cast_to" json:"cast_to,omitempty"`
	Template     string      `mapstructure:"template" json:"template,omitempty"`
	DefaultValue ParamsValue `mapstructure:"default_value" json:"default_value,omitempty"`
}

func (*DynamicParamValue) ParameterValuer

func (dpv *DynamicParamValue) ParameterValuer()

type DynamicParameter

type DynamicParameter struct {
	// DynamicValue - The dynamic value settings that received from config
	DynamicValue *DynamicParamValue
	// contains filtered or unexported fields
}

func NewDynamicParameter

func NewDynamicParameter(def *ParameterDefinition, driver *Driver) *DynamicParameter

func (*DynamicParameter) GetDefinition

func (dp *DynamicParameter) GetDefinition() *ParameterDefinition

func (*DynamicParameter) Init

func (dp *DynamicParameter) Init(columnParameters map[string]*StaticParameter, dynamicValue *DynamicParamValue) (warnings ValidationWarnings, err error)

func (*DynamicParameter) IsDynamic

func (dp *DynamicParameter) IsDynamic() bool

func (*DynamicParameter) IsEmpty

func (dp *DynamicParameter) IsEmpty() (bool, error)

func (*DynamicParameter) RawValue

func (dp *DynamicParameter) RawValue() (ParamsValue, error)

func (*DynamicParameter) Scan

func (dp *DynamicParameter) Scan(dest any) error

func (*DynamicParameter) SetRecord

func (dp *DynamicParameter) SetRecord(r *Record)

func (*DynamicParameter) Value

func (dp *DynamicParameter) Value() (value any, err error)

type DynamicParameterContext

type DynamicParameterContext struct {
	// contains filtered or unexported fields
}

func NewDynamicParameterContext

func NewDynamicParameterContext(column *Column) *DynamicParameterContext

func (*DynamicParameterContext) DecodeValue

func (dpc *DynamicParameterContext) DecodeValue(v any) (any, error)

func (*DynamicParameterContext) DecodeValueByColumn

func (dpc *DynamicParameterContext) DecodeValueByColumn(name string, v any) (any, error)

func (*DynamicParameterContext) DecodeValueByType

func (dpc *DynamicParameterContext) DecodeValueByType(name string, v any) (any, error)

func (*DynamicParameterContext) EncodeValue

func (dpc *DynamicParameterContext) EncodeValue(v any) (any, error)

func (*DynamicParameterContext) EncodeValueByColumn

func (dpc *DynamicParameterContext) EncodeValueByColumn(name string, v any) (any, error)

func (*DynamicParameterContext) EncodeValueByType

func (dpc *DynamicParameterContext) EncodeValueByType(name string, v any) (any, error)

func (*DynamicParameterContext) GetColumnType

func (dpc *DynamicParameterContext) GetColumnType() string

func (*DynamicParameterContext) GetColumnValue

func (dpc *DynamicParameterContext) GetColumnValue(name string) (any, error)

func (*DynamicParameterContext) GetRawColumnValue

func (dpc *DynamicParameterContext) GetRawColumnValue(name string) (any, error)

func (*DynamicParameterContext) GetRawValue

func (dpc *DynamicParameterContext) GetRawValue() (any, error)

func (*DynamicParameterContext) GetValue

func (dpc *DynamicParameterContext) GetValue() (any, error)

type DynamicParameters

type DynamicParameters map[string]*DynamicParamValue

type Exclusion

func NewExclusion

func NewExclusion(schema, name, definition string, oid Oid, columns []AttNum) *Exclusion

func (*Exclusion) IsAffected

func (e *Exclusion) IsAffected(column *Column, columnProperties *ColumnProperties) (w ValidationWarnings)

func (*Exclusion) Type

func (e *Exclusion) Type() string

type ForeignKey

type ForeignKey struct {
	DefaultConstraintDefinition
	// ReferencedTable - table that has primary key definition on that discovering table is referencing
	ReferencedTable LinkedTable `json:"referencedTable,omitempty"`
}

func NewForeignKey

func NewForeignKey(schema, name, definition string, oid Oid, columns []AttNum, referencedTable LinkedTable) *ForeignKey

func (*ForeignKey) IsAffected

func (fk *ForeignKey) IsAffected(column *Column, columnProperties *ColumnProperties) (w ValidationWarnings)

func (*ForeignKey) Type

func (fk *ForeignKey) Type() string

type InteractionApi

type InteractionApi interface {
	// SetWriter - assign writer
	SetWriter(w io.Writer)
	// SetReader - assign reader
	SetReader(r io.Reader)
	// GetRowDriverFromRecord - get from toolkit.Record all the required attributes as a toolkit.RowDriver instance
	GetRowDriverFromRecord(r *Record) (RowDriver, error)
	// SetRowDriverToRecord - set transformed toolkit.RowDriver to the toolkit.Record
	SetRowDriverToRecord(rd RowDriver, r *Record) error
	// Encode - write encoded data with \n symbol in the end into io.Writer
	Encode(ctx context.Context, row RowDriver) error
	// Decode - read data with new line from io.Reader and encode to toolkit.RowDriver
	Decode(ctx context.Context) (RowDriver, error)
	// Clean - clean cached Record
	Clean()
}

InteractionApi - API for interaction with Cmd transformer. It must implement context cancellation, RW timeouts, encode-decode operations, extracting DTO and assigning received DTO to the toolkit.Record

func NewApi

func NewApi(rowDriverParams *DriverParams, transferringColumns []*Column, affectedColumns []*Column, driver *Driver) (InteractionApi, error)

type JsonApi

type JsonApi struct {
	// contains filtered or unexported fields
}

func NewJsonApi

func NewJsonApi(
	transferringColumns []*Column, affectedColumns []*Column, params *DriverParams,
) (*JsonApi, error)

func (*JsonApi) Clean

func (j *JsonApi) Clean()

func (*JsonApi) Decode

func (j *JsonApi) Decode(ctx context.Context) (RowDriver, error)

func (*JsonApi) Encode

func (j *JsonApi) Encode(ctx context.Context, row RowDriver) (err error)

func (*JsonApi) GetRowDriverFromRecord

func (j *JsonApi) GetRowDriverFromRecord(r *Record) (RowDriver, error)

func (*JsonApi) SetReader

func (j *JsonApi) SetReader(r io.Reader)

func (*JsonApi) SetRowDriverToRecord

func (j *JsonApi) SetRowDriverToRecord(rd RowDriver, r *Record) error

func (*JsonApi) SetWriter

func (j *JsonApi) SetWriter(w io.Writer)

type JsonRecordWithAttrNames

type JsonRecordWithAttrNames struct {
	// contains filtered or unexported fields
}

func NewJsonRecordWithAttrNamesText

func NewJsonRecordWithAttrNamesText(columns []*Column) *JsonRecordWithAttrNames

func (*JsonRecordWithAttrNames) Clean

func (rr *JsonRecordWithAttrNames) Clean()

func (*JsonRecordWithAttrNames) Decode

func (rr *JsonRecordWithAttrNames) Decode(data []byte) error

func (*JsonRecordWithAttrNames) Encode

func (rr *JsonRecordWithAttrNames) Encode() ([]byte, error)

func (*JsonRecordWithAttrNames) GetColumn

func (rr *JsonRecordWithAttrNames) GetColumn(idx int) (*RawValue, error)

func (*JsonRecordWithAttrNames) Length

func (rr *JsonRecordWithAttrNames) Length() int

func (*JsonRecordWithAttrNames) MarshalJSON

func (rr *JsonRecordWithAttrNames) MarshalJSON() ([]byte, error)

func (*JsonRecordWithAttrNames) SetColumn

func (rr *JsonRecordWithAttrNames) SetColumn(idx int, v *RawValue) error

func (*JsonRecordWithAttrNames) UnmarshalJSON

func (rr *JsonRecordWithAttrNames) UnmarshalJSON(data []byte) error

type JsonRecordWithAttrNamesBinary

type JsonRecordWithAttrNamesBinary struct {
	// contains filtered or unexported fields
}

func NewJsonRecordWithAttrNamesBinary

func NewJsonRecordWithAttrNamesBinary(columns []*Column) *JsonRecordWithAttrNamesBinary

func (*JsonRecordWithAttrNamesBinary) Clean

func (rr *JsonRecordWithAttrNamesBinary) Clean()

func (*JsonRecordWithAttrNamesBinary) Decode

func (rr *JsonRecordWithAttrNamesBinary) Decode(data []byte) error

func (*JsonRecordWithAttrNamesBinary) Encode

func (rr *JsonRecordWithAttrNamesBinary) Encode() ([]byte, error)

func (*JsonRecordWithAttrNamesBinary) GetColumn

func (rr *JsonRecordWithAttrNamesBinary) GetColumn(idx int) (*RawValue, error)

func (*JsonRecordWithAttrNamesBinary) Length

func (rr *JsonRecordWithAttrNamesBinary) Length() int

func (*JsonRecordWithAttrNamesBinary) MarshalJSON

func (rr *JsonRecordWithAttrNamesBinary) MarshalJSON() ([]byte, error)

func (*JsonRecordWithAttrNamesBinary) SetColumn

func (rr *JsonRecordWithAttrNamesBinary) SetColumn(idx int, v *RawValue) error

func (*JsonRecordWithAttrNamesBinary) UnmarshalJSON

func (rr *JsonRecordWithAttrNamesBinary) UnmarshalJSON(data []byte) error

type LinkedTable

type LinkedTable struct {
	// Schema - table schema name
	Schema string `json:"schema"`
	// Name - table name
	Name string `json:"name"`
	// Oid - table oid
	Oid Oid `json:"oid"`
	// Constraint - linked table constraint
	Constraint Constraint `json:"constraint,omitempty"`
}

LinkedTable - table that involved into constraint, required for ForeignKey and PrimaryKeyReferences

type Meta

type Meta struct {
	Table               *Table            `json:"table"`
	Parameters          *Parameters       `json:"parameters"`
	Types               []*Type           `json:"types"`
	ColumnsTypeOverride map[string]string `json:"columns_type_override"`
}

type NewRowDriverFunc

type NewRowDriverFunc func() RowDriver

type NewTransformerFunc

type NewTransformerFunc func(ctx context.Context, driver *Driver, parameters map[string]Parameterizer) (
	Transformer, ValidationWarnings, error,
)

type NullType

type NullType string
var NullValue NullType = "\\N"

type Oid

type Oid int

type ParameterDefinition

type ParameterDefinition struct {
	// Name - name of the parameter. Must be unique in the whole Transformer parameters slice
	Name string `mapstructure:"name" json:"name"`
	// Description - description of the parameter. Should contain the brief info about parameter
	Description string `mapstructure:"description" json:"description"`
	// Required - shows that parameter is required, and we expect we have to receive this value from config.
	// Event when DefaultValue is defined it will case error
	Required bool `mapstructure:"required" json:"required"`
	// IsColumn - shows is this parameter column related. If so ColumnProperties must be defined and assigned
	// otherwise it may cause an unhandled behaviour
	IsColumn bool `mapstructure:"is_column" json:"is_column"`
	// IsColumnContainer - describe is parameter container map or list with multiple columns inside. It allows us to
	IsColumnContainer bool `mapstructure:"is_column_container" json:"is_column_container"`
	// LinkColumnParameter - link with parameter with provided name. This is required if performing raw value encoding
	// depends on the provided column type and/or relies on the database Driver
	LinkColumnParameter string `mapstructure:"link_column_parameter" json:"link_column_parameter,omitempty"`
	// CastDbType - name of PostgreSQL type that would be used for Decoding raw value to the real go type. Is this
	// type does not exist will cause an error
	CastDbType string `mapstructure:"cast_db_type" json:"cast_db_type,omitempty"`
	// GlobalEnvVariable - the nane of the global environment variable that can be used on empty input
	GetFromGlobalEnvVariable string `mapstructure:"get_from_global_env_variable" json:"get_from_global_env_variable,omitempty"`
	// DynamicModeProperties - shows that parameter support dynamic mode and contains allowed types and unmarshaler
	DynamicModeProperties *DynamicModeProperties
	// DefaultValue - default value of the parameter
	DefaultValue ParamsValue `mapstructure:"default_value" json:"default_value,omitempty"`
	// ColumnProperties - detail info about expected column properties that may help to diagnose the table schema
	// and perform validation procedure Plays only with IsColumn
	ColumnProperties *ColumnProperties `mapstructure:"column_properties" json:"column_properties,omitempty"`
	// SupportTemplate - shows that parameter supports golang template and might be calculated dynamically
	SupportTemplate bool `mapstructure:"support_template" json:"support_template,omitempty"`
	// Unmarshaller - unmarshal function for the parameter raw data []byte. Using by default json.Unmarshal function
	Unmarshaller Unmarshaller `json:"-"`
	// RawValueValidator - raw value validator function that performs assertion and cause ValidationWarnings if it
	// has violations
	RawValueValidator RawValueValidator `json:"-"`
	// AllowedValues - slice of values which allowed to use
	AllowedValues []ParamsValue `mapstructure:"allowed_values" json:"allowed_values,omitempty"`
}

ParameterDefinition - wide parameter entity definition that contains properties that allows to check schema, find affection, cast variable using some features and so on. It may be defined and assigned ot the TransformerDefinition of the transformer if transformer has any parameters

func MustNewParameterDefinition

func MustNewParameterDefinition(name string, description string) *ParameterDefinition

func NewParameterDefinition

func NewParameterDefinition(name string, description string) (*ParameterDefinition, error)

func (*ParameterDefinition) SetAllowedValues

func (p *ParameterDefinition) SetAllowedValues(v ...ParamsValue) *ParameterDefinition

func (*ParameterDefinition) SetCastDbType

func (p *ParameterDefinition) SetCastDbType(v string) *ParameterDefinition

func (*ParameterDefinition) SetDefaultValue

func (p *ParameterDefinition) SetDefaultValue(v ParamsValue) *ParameterDefinition

func (*ParameterDefinition) SetDynamicMode

func (*ParameterDefinition) SetGetFromGlobalEnvVariable

func (p *ParameterDefinition) SetGetFromGlobalEnvVariable(v string) *ParameterDefinition

func (*ParameterDefinition) SetIsColumn

func (p *ParameterDefinition) SetIsColumn(columnProperties *ColumnProperties) *ParameterDefinition

func (*ParameterDefinition) SetIsColumnContainer

func (p *ParameterDefinition) SetIsColumnContainer(v bool) *ParameterDefinition

func (*ParameterDefinition) SetLinkParameter

func (p *ParameterDefinition) SetLinkParameter(name string) *ParameterDefinition

func (*ParameterDefinition) SetRawValueValidator

func (p *ParameterDefinition) SetRawValueValidator(validator RawValueValidator) *ParameterDefinition

func (*ParameterDefinition) SetRequired

func (p *ParameterDefinition) SetRequired(v bool) *ParameterDefinition

func (*ParameterDefinition) SetSupportTemplate

func (p *ParameterDefinition) SetSupportTemplate(v bool) *ParameterDefinition

func (*ParameterDefinition) SetUnmarshaler

func (p *ParameterDefinition) SetUnmarshaler(unmarshaler Unmarshaller) *ParameterDefinition

type ParameterValuer

type ParameterValuer interface {
	Value()
}

type Parameterizer

type Parameterizer interface {
	Value() (value any, err error)
	RawValue() (rawValue ParamsValue, err error)
	Scan(dest any) (err error)
	GetDefinition() *ParameterDefinition
	IsDynamic() bool
	IsEmpty() (bool, error)
}

type Parameters

type Parameters struct {
	Static  StaticParameters  `json:"static,omitempty"`
	Dynamic DynamicParameters `json:"dynamic,omitempty"`
}

type ParamsValue

type ParamsValue []byte

func (*ParamsValue) ParameterValuer

func (pv *ParamsValue) ParameterValuer()

func (*ParamsValue) UnmarshalJSON

func (pv *ParamsValue) UnmarshalJSON(data []byte) error

type PrimaryKey

type PrimaryKey struct {
	DefaultConstraintDefinition
	References []*LinkedTable
}

func NewPrimaryKey

func NewPrimaryKey(schema, name, definition string, oid Oid, columns []AttNum) *PrimaryKey

func (*PrimaryKey) IsAffected

func (pk *PrimaryKey) IsAffected(column *Column, columnProperties *ColumnProperties) (w ValidationWarnings)

func (*PrimaryKey) Type

func (pk *PrimaryKey) Type() string

type RawRecord

type RawRecord map[int]*RawValue

func (*RawRecord) Clean

func (rr *RawRecord) Clean()

func (*RawRecord) Decode

func (rr *RawRecord) Decode(data []byte) error

func (*RawRecord) Encode

func (rr *RawRecord) Encode() ([]byte, error)

func (*RawRecord) GetColumn

func (rr *RawRecord) GetColumn(idx int) (*RawValue, error)

func (*RawRecord) Length

func (rr *RawRecord) Length() int

func (*RawRecord) SetColumn

func (rr *RawRecord) SetColumn(idx int, v *RawValue) error

type RawRecordAttrs

type RawRecordAttrs map[string]*RawValue

type RawRecordAttrsText

type RawRecordAttrsText map[string]*RawValueStr

type RawRecordCsv

type RawRecordCsv struct {
	Data []string
	// contains filtered or unexported fields
}

func NewRawRecordCsv

func NewRawRecordCsv(size int, columnRemap []*Column) *RawRecordCsv

func (*RawRecordCsv) Clean

func (rr *RawRecordCsv) Clean()

func (*RawRecordCsv) Decode

func (rr *RawRecordCsv) Decode(data []byte) (err error)

func (*RawRecordCsv) Encode

func (rr *RawRecordCsv) Encode() ([]byte, error)

func (*RawRecordCsv) GetColumn

func (rr *RawRecordCsv) GetColumn(idx int) (*RawValue, error)

func (*RawRecordCsv) Length

func (rr *RawRecordCsv) Length() int

func (*RawRecordCsv) SetColumn

func (rr *RawRecordCsv) SetColumn(idx int, v *RawValue) error

type RawRecordStr

type RawRecordStr map[int]*RawValueStr

RawRecordStr - Record data transfer object for interaction with custom transformer via PIPE

func (*RawRecordStr) Clean

func (rrs *RawRecordStr) Clean()

func (*RawRecordStr) Decode

func (rrs *RawRecordStr) Decode(data []byte) error

func (*RawRecordStr) Encode

func (rrs *RawRecordStr) Encode() ([]byte, error)

func (*RawRecordStr) GetColumn

func (rrs *RawRecordStr) GetColumn(idx int) (*RawValue, error)

func (*RawRecordStr) Length

func (rrs *RawRecordStr) Length() int

func (*RawRecordStr) SetColumn

func (rrs *RawRecordStr) SetColumn(idx int, v *RawValue) error

type RawRecordText

type RawRecordText []byte
var DefaultNullSeq RawRecordText = []byte("\\N")

func NewRawRecordText

func NewRawRecordText() *RawRecordText

func (*RawRecordText) Clean

func (r *RawRecordText) Clean()

func (*RawRecordText) Decode

func (r *RawRecordText) Decode(data []byte) error

func (*RawRecordText) Encode

func (r *RawRecordText) Encode() ([]byte, error)

func (*RawRecordText) GetColumn

func (r *RawRecordText) GetColumn(idx int) (*RawValue, error)

func (*RawRecordText) Length

func (r *RawRecordText) Length() int

func (*RawRecordText) SetColumn

func (r *RawRecordText) SetColumn(idx int, v *RawValue) error

type RawValue

type RawValue struct {
	Data   []byte `json:"d"`
	IsNull bool   `json:"n"`
}

func NewRawValue

func NewRawValue(data []byte, isNull bool) *RawValue

type RawValueStr

type RawValueStr struct {
	Data   *string `json:"d"`
	IsNull bool    `json:"n"`
}

func NewRawValueStr

func NewRawValueStr(data []byte, isNull bool) *RawValueStr

type RawValueValidator

type RawValueValidator func(p *ParameterDefinition, v ParamsValue) (ValidationWarnings, error)

type Record

type Record struct {
	Driver *Driver
	Row    RowDriver
	// contains filtered or unexported fields
}

func NewRecord

func NewRecord(driver *Driver) *Record

func (*Record) Encode

func (r *Record) Encode() (RowDriver, error)

func (*Record) GetColumnValueByIdx

func (r *Record) GetColumnValueByIdx(idx int) (*Value, error)

func (*Record) GetColumnValueByName

func (r *Record) GetColumnValueByName(name string) (*Value, error)

func (*Record) GetRawColumnValueByIdx

func (r *Record) GetRawColumnValueByIdx(idx int) (*RawValue, error)

func (*Record) GetRawColumnValueByName

func (r *Record) GetRawColumnValueByName(name string) (*RawValue, error)

func (*Record) GetTuple

func (r *Record) GetTuple() (Tuple, error)

func (*Record) ScanColumnValueByIdx

func (r *Record) ScanColumnValueByIdx(idx int, v any) (bool, error)

ScanColumnValueByIdx - scan data from column with name into v and return isNull property and error

func (*Record) ScanColumnValueByName

func (r *Record) ScanColumnValueByName(name string, v any) (bool, error)

func (*Record) SetColumnValueByIdx

func (r *Record) SetColumnValueByIdx(idx int, v any) error

func (*Record) SetColumnValueByName

func (r *Record) SetColumnValueByName(name string, v any) error

SetColumnValueByName - set transformed attribute to the tuple

func (*Record) SetRawColumnValueByIdx

func (r *Record) SetRawColumnValueByIdx(idx int, value *RawValue) error

func (*Record) SetRawColumnValueByName

func (r *Record) SetRawColumnValueByName(name string, value *RawValue) error

func (*Record) SetRow

func (r *Record) SetRow(row RowDriver)

type RecordContext

type RecordContext struct {
	// contains filtered or unexported fields
}

func NewRecordContext

func NewRecordContext() *RecordContext

func (*RecordContext) Clean

func (rc *RecordContext) Clean()

func (*RecordContext) DecodeValueByColumn

func (rc *RecordContext) DecodeValueByColumn(name string, v any) (any, error)

DecodeValueByColumn - decode value from string or NullValue to the real type using column type

func (*RecordContext) DecodeValueByType

func (rc *RecordContext) DecodeValueByType(name string, v any) (any, error)

DecodeValueByType - decode value from string or NullValue to the real type using type

func (*RecordContext) EncodeValueByColumn

func (rc *RecordContext) EncodeValueByColumn(name string, v any) (any, error)

EncodeValueByColumn - encode value from real type to the string or NullValue using column type

func (*RecordContext) EncodeValueByType

func (rc *RecordContext) EncodeValueByType(name string, v any) (any, error)

EncodeValueByType - encode value from real type to the string or NullValue using type

func (*RecordContext) GetChangedColumns

func (rc *RecordContext) GetChangedColumns() map[string]struct{}

func (*RecordContext) GetColumnType

func (rc *RecordContext) GetColumnType(name string) (string, error)

func (*RecordContext) GetColumnValue

func (rc *RecordContext) GetColumnValue(name string) (any, error)

func (*RecordContext) GetRawColumnValue

func (rc *RecordContext) GetRawColumnValue(name string) (any, error)

func (*RecordContext) SetColumnValue

func (rc *RecordContext) SetColumnValue(name string, v any) (bool, error)

func (*RecordContext) SetRawColumnValue

func (rc *RecordContext) SetRawColumnValue(name string, v any) (bool, error)

func (*RecordContext) SetRecord

func (rc *RecordContext) SetRecord(r *Record)

type Reference

type Reference struct {
	Idx    int
	Schema string
	Name   string
	// ReferencedKeys - list of foreign keys of current table
	ReferencedKeys []string
	IsNullable     bool
}

type RowDriver

type RowDriver interface {
	// GetColumn - get raw []byte value by column idx
	GetColumn(idx int) (*RawValue, error)
	// SetColumn - set RawValue value by column idx to the current row
	SetColumn(idx int, v *RawValue) error
	// Encode - encode the whole row to the []byte representation of RowDriver. It would be CSV
	// line or JSON object, etc.
	Encode() ([]byte, error)
	// Decode - decode []bytes to RowDriver instance
	Decode([]byte) error
	// Length - count of attributes in the row
	Length() int
	// Clean - clean the state
	Clean()
}

RowDriver - represents methods for interacts with any transferring format It might be COPY, CSV, JSON, etc. See implementation pgcopy.Row RowDriver must keep the current row state

type StaticParameter

type StaticParameter struct {

	// Column - column of the table that was assigned in the parsing procedure according to provided Column name in
	// parameter value. In this case value has textual column name
	Column *Column
	// contains filtered or unexported fields
}

func NewStaticParameter

func NewStaticParameter(def *ParameterDefinition, driver *Driver) *StaticParameter

func (*StaticParameter) GetDefinition

func (sp *StaticParameter) GetDefinition() *ParameterDefinition

func (*StaticParameter) Init

func (sp *StaticParameter) Init(columnParams map[string]*StaticParameter, rawValue ParamsValue) (ValidationWarnings, error)

func (*StaticParameter) IsDynamic

func (sp *StaticParameter) IsDynamic() bool

func (*StaticParameter) IsEmpty

func (sp *StaticParameter) IsEmpty() (bool, error)

func (*StaticParameter) RawValue

func (sp *StaticParameter) RawValue() (ParamsValue, error)

func (*StaticParameter) Scan

func (sp *StaticParameter) Scan(dest any) error

func (*StaticParameter) Value

func (sp *StaticParameter) Value() (any, error)

type StaticParameterContext

type StaticParameterContext struct {
	// contains filtered or unexported fields
}

func NewStaticParameterContext

func NewStaticParameterContext(d *Driver, linkedColumnName string) *StaticParameterContext

func (*StaticParameterContext) DecodeValue

func (spc *StaticParameterContext) DecodeValue(v any) (any, error)

func (*StaticParameterContext) DecodeValueByColumn

func (spc *StaticParameterContext) DecodeValueByColumn(name string, v any) (any, error)

func (*StaticParameterContext) DecodeValueByType

func (spc *StaticParameterContext) DecodeValueByType(name string, v any) (any, error)

func (*StaticParameterContext) EncodeValue

func (spc *StaticParameterContext) EncodeValue(v any) (any, error)

func (*StaticParameterContext) EncodeValueByColumn

func (spc *StaticParameterContext) EncodeValueByColumn(name string, v any) (any, error)

func (*StaticParameterContext) EncodeValueByType

func (spc *StaticParameterContext) EncodeValueByType(name string, v any) (any, error)

func (*StaticParameterContext) GetColumnType

func (spc *StaticParameterContext) GetColumnType(name string) (string, error)

type StaticParameters

type StaticParameters map[string]ParamsValue

func (*StaticParameters) MarshalJSON

func (p *StaticParameters) MarshalJSON() ([]byte, error)

type Table

type Table struct {
	Schema     string    `json:"schema"`
	Name       string    `json:"name"`
	Oid        Oid       `json:"oid"`
	Columns    []*Column `json:"columns"`
	Kind       string    `json:"kind"`
	Parent     Oid       `json:"parent"`
	Children   []Oid     `json:"children"`
	Size       int64     `json:"size"`
	PrimaryKey []string  `json:"primary_key"`
	// RootPtSchema, RootPtName, RootPtOid - the first parent of the partitioned table
	RootPtSchema string       `json:"root_pt_schema"`
	RootPtName   string       `json:"root_pt_name"`
	RootPtOid    Oid          `json:"root_pt_oid"`
	Constraints  []Constraint `json:"-"`
}

func (*Table) Validate

func (t *Table) Validate() error

type TestRowDriver

type TestRowDriver struct {
	// contains filtered or unexported fields
}

func (*TestRowDriver) Clean

func (trd *TestRowDriver) Clean()

func (*TestRowDriver) Decode

func (trd *TestRowDriver) Decode([]byte) error

func (*TestRowDriver) Encode

func (trd *TestRowDriver) Encode() ([]byte, error)

func (*TestRowDriver) GetColumn

func (trd *TestRowDriver) GetColumn(idx int) (*RawValue, error)

func (*TestRowDriver) Length

func (trd *TestRowDriver) Length() int

func (*TestRowDriver) SetColumn

func (trd *TestRowDriver) SetColumn(idx int, v *RawValue) error

type TextApi

type TextApi struct {
	// contains filtered or unexported fields
}

func NewTextApi

func NewTextApi(columnIdx int, skipOriginalData bool) (*TextApi, error)

func (*TextApi) Clean

func (ta *TextApi) Clean()

func (*TextApi) Decode

func (ta *TextApi) Decode(ctx context.Context) (RowDriver, error)

func (*TextApi) Encode

func (ta *TextApi) Encode(ctx context.Context, row RowDriver) (err error)

func (*TextApi) GetRowDriverFromRecord

func (ta *TextApi) GetRowDriverFromRecord(r *Record) (RowDriver, error)

func (*TextApi) SetReader

func (ta *TextApi) SetReader(r io.Reader)

func (*TextApi) SetRowDriverToRecord

func (ta *TextApi) SetRowDriverToRecord(rd RowDriver, r *Record) error

func (*TextApi) SetWriter

func (ta *TextApi) SetWriter(w io.Writer)

type Transformer

type Transformer interface {
	Validate(ctx context.Context) (ValidationWarnings, error)
	Transform(ctx context.Context, r *Record) error
}

type TransformerDefinition

type TransformerDefinition struct {
	Name             string                 `json:"name"`
	Description      string                 `json:"description"`
	Parameters       []*ParameterDefinition `json:"parameters"`
	Validate         bool                   `json:"validate"`
	ExpectedExitCode int                    `json:"expected_exit_code"`
	Driver           *DriverParams          `json:"driver"`
	New              NewTransformerFunc     `json:"-"`
}

func NewTransformerDefinition

func NewTransformerDefinition(name string, makeFunc NewTransformerFunc) *TransformerDefinition

func (*TransformerDefinition) AddParameter

func (*TransformerDefinition) SetDescription

func (d *TransformerDefinition) SetDescription(v string) *TransformerDefinition

func (*TransformerDefinition) SetExpectedExitCode

func (d *TransformerDefinition) SetExpectedExitCode(v int) *TransformerDefinition

func (*TransformerDefinition) SetMode

func (*TransformerDefinition) SetValidate

type TriggerConstraint

type TriggerConstraint DefaultConstraintDefinition

func NewTriggerConstraint

func NewTriggerConstraint(schema, name, definition string, oid Oid, columns []AttNum) *TriggerConstraint

func (*TriggerConstraint) IsAffected

func (tc *TriggerConstraint) IsAffected(column *Column, columnProperties *ColumnProperties) (w ValidationWarnings)

func (*TriggerConstraint) Type

func (tc *TriggerConstraint) Type() string

type Tuple

type Tuple map[string]*Value

type Type

type Type struct {
	// Oid - pg_type.oid
	Oid Oid `json:"oid,omitempty"`
	// ChainOids - list of inherited types (oid) till the main base type
	ChainOids []Oid `json:"chain_oids,omitempty"`
	// ChainNames - list of inherited types (name) till the main base type
	ChainNames []string `json:"chain_names,omitempty"`
	// Schema - type schema name
	Schema string `json:"schema,omitempty"`
	// Name - (pg_type.typname) type name
	Name string `json:"name,omitempty"`
	// Length - (pg_type.typelen) for a fixed-size type, typlen is the number of bytes in the internal representation of the type.
	// But for a variable-length type, typlen is negative. -1 indicates a “varlena” type (one that has a length
	// word), -2 indicates a null-terminated C string.
	Length int `json:"length,omitempty"`
	// Kind - (pg_type.typtype) type of type
	Kind rune `json:"kind,omitempty"`
	// ComposedRelation - (pg_type.typrelid) if composite type reference to the table that defines the structure
	ComposedRelation Oid `json:"composed_relation,omitempty"`
	// ElementType - (pg_type.typelem) references to the item of the array type
	ElementType Oid `json:"element_type,omitempty"`
	// ArrayType - (pg_type.typarray) references to the array type
	ArrayType Oid `json:"array_type,omitempty"`
	// NotNull - (pg_type.typnotnull) shows is this type nullable. For domains only
	NotNull bool `json:"not_null,omitempty"`
	// BaseType - (pg_type.typbasetype) references to the base type
	BaseType Oid `json:"base_type,omitempty"`
	//Check - definition of check constraint
	Check *Check `json:"check,omitempty"`
	// RootBuiltInTypeOid - defines builtin type oid that might be used for decoding and encoding
	RootBuiltInTypeOid Oid `json:"root_built_in_type_oid,omitempty"`
	// RootBuiltInTypeOid - defines builtin type name that might be used for decoding and encoding
	RootBuiltInTypeName string `json:"root_built_in_type_name,omitempty"`
}

Type - describes pg_catalog.pg_type

func GetCustomType

func GetCustomType(customTypes []*Type, typeName string) *Type

func (*Type) IsAffected

func (t *Type) IsAffected(p *StaticParameter) (w ValidationWarnings)

type TypeCastDefinition

type TypeCastDefinition struct {
	Cast        TypeCastFunc
	InputTypes  []string
	OutputTypes []string
}

func (*TypeCastDefinition) ValidateTypes

func (tcd *TypeCastDefinition) ValidateTypes(inputType, outputType string) bool

type TypeCastFunc

type TypeCastFunc func(driver *Driver, input []byte) (output []byte, err error)

TypeCastFunc the function implements type casting from one to another

type TypeCaster

type TypeCaster struct {
	// contains filtered or unexported fields
}

func (*TypeCaster) Cast

func (tc *TypeCaster) Cast(driver *Driver, input []byte) (output []byte, err error)

type Unique

func NewUnique

func NewUnique(schema, name, definition string, oid Oid, columns []AttNum) *Unique

func (*Unique) IsAffected

func (u *Unique) IsAffected(column *Column, columnProperties *ColumnProperties) (w ValidationWarnings)

func (*Unique) Type

func (u *Unique) Type() string

type Unmarshaller

type Unmarshaller func(parameter *ParameterDefinition, driver *Driver, src ParamsValue) (any, error)

type ValidationWarning

type ValidationWarning struct {
	Msg      string         `json:"msg,omitempty"`
	Severity string         `json:"severity,omitempty"`
	Meta     map[string]any `json:"meta,omitempty"`
	Hash     string         `json:"hash"`
}

func NewValidationWarning

func NewValidationWarning() *ValidationWarning

func (*ValidationWarning) AddMeta

func (re *ValidationWarning) AddMeta(key string, value any) *ValidationWarning

func (*ValidationWarning) MakeHash

func (re *ValidationWarning) MakeHash()

func (*ValidationWarning) SetMsg

func (re *ValidationWarning) SetMsg(msg string) *ValidationWarning

func (*ValidationWarning) SetMsgf

func (re *ValidationWarning) SetMsgf(msg string, args ...any) *ValidationWarning

func (*ValidationWarning) SetSeverity

func (re *ValidationWarning) SetSeverity(severity string) *ValidationWarning

type ValidationWarnings

type ValidationWarnings []*ValidationWarning

func InitParameters

func InitParameters(
	driver *Driver, paramDef []*ParameterDefinition, staticValues map[string]ParamsValue,
	dynamicValues map[string]*DynamicParamValue,
) (map[string]Parameterizer, ValidationWarnings, error)

func (ValidationWarnings) IsFatal

func (re ValidationWarnings) IsFatal() bool

type Value

type Value struct {
	Value  any
	IsNull bool
}

func NewValue

func NewValue(v any, isNull bool) *Value

type WhenCond

type WhenCond struct {
	// contains filtered or unexported fields
}

WhenCond - A condition that should be evaluated to determine if the record should be processed.

func (*WhenCond) Evaluate

func (wc *WhenCond) Evaluate(r *Record) (bool, error)

Evaluate - evaluates the when condition. If the when condition is empty, it will always return true.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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