toolkit

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

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 added in v0.2.0

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

func BoolToInt added in v0.2.0

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

func CastFloatToInt added in v0.2.0

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

func CastIntToFloat added in v0.2.0

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

func DefaultDatabaseTypeUnmarshaler added in v0.2.0

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

func FuncMap added in v0.2.0

func FuncMap() template.FuncMap

func GetAffectedAndTransferringColumns

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

func GetCanonicalTypeName added in v0.2.0

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

func GetDriverAndRecord added in v0.2.0

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 added in v0.2.0

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

func IsTypeAllowed added in v0.2.0

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

func IsTypeAllowedWithTypeMap added in v0.2.0

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

func IsTypeCustom added in v0.2.0

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

func NewDriver

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

func NewTypeCaster added in v0.2.0

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

func NewWhenCond added in v0.2.1

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 added in v0.2.0

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

func NoiseFloat added in v0.2.0

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

func NoiseInt added in v0.2.0

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

func PrintValidationWarnings added in v0.2.1

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

func RandomBool added in v0.2.0

func RandomBool(r *rand.Rand) bool

func RandomDate added in v0.2.0

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

func RandomFloat added in v0.2.0

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

func RandomInt added in v0.2.0

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

func RandomString added in v0.2.0

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

func Round added in v0.2.0

func Round(precision int, num float64) float64

func ScanPointer added in v0.2.0

func ScanPointer(src, dest any) error

func TruncateDate added in v0.2.0

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 added in v0.1.7

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 added in v0.2.0

func (c *Column) GetColumnSize() int

func (*Column) GetType added in v0.2.0

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

func (*Column) GetTypeOid added in v0.2.0

func (c *Column) GetTypeOid() Oid

func (*Column) OverrideType added in v0.2.1

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 added in v0.1.7

type DatabaseSchema []*Table

func (DatabaseSchema) Diff added in v0.1.7

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

type DatabaseTypeUnmarshaler added in v0.2.0

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 added in v0.1.7

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 added in v0.2.0

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 added in v0.1.7

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 added in v0.1.7

func (dp *DriverParams) Validate() error

Validate - validate driver params and set default values if needed

type DynamicModeProperties added in v0.2.0

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

func NewDynamicModeProperties added in v0.2.0

func NewDynamicModeProperties() *DynamicModeProperties

func (*DynamicModeProperties) SetCompatibleTypes added in v0.2.0

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

func (*DynamicModeProperties) SetUnmarshaler added in v0.2.0

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

type DynamicParamValue added in v0.2.0

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 added in v0.2.0

func (dpv *DynamicParamValue) ParameterValuer()

type DynamicParameter added in v0.2.0

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

func NewDynamicParameter added in v0.2.0

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

func (*DynamicParameter) GetDefinition added in v0.2.0

func (dp *DynamicParameter) GetDefinition() *ParameterDefinition

func (*DynamicParameter) Init added in v0.2.0

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

func (*DynamicParameter) IsDynamic added in v0.2.0

func (dp *DynamicParameter) IsDynamic() bool

func (*DynamicParameter) IsEmpty added in v0.2.0

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

func (*DynamicParameter) RawValue added in v0.2.0

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

func (*DynamicParameter) Scan added in v0.2.0

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

func (*DynamicParameter) SetRecord added in v0.2.0

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

func (*DynamicParameter) Value added in v0.2.0

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

type DynamicParameterContext added in v0.2.0

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

func NewDynamicParameterContext added in v0.2.0

func NewDynamicParameterContext(column *Column) *DynamicParameterContext

func (*DynamicParameterContext) DecodeValue added in v0.2.0

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

func (*DynamicParameterContext) DecodeValueByColumn added in v0.2.0

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

func (*DynamicParameterContext) DecodeValueByType added in v0.2.0

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

func (*DynamicParameterContext) EncodeValue added in v0.2.0

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

func (*DynamicParameterContext) EncodeValueByColumn added in v0.2.0

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

func (*DynamicParameterContext) EncodeValueByType added in v0.2.0

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

func (*DynamicParameterContext) GetColumnRawValue added in v0.2.0

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

func (*DynamicParameterContext) GetColumnType added in v0.2.0

func (dpc *DynamicParameterContext) GetColumnType() string

func (*DynamicParameterContext) GetColumnValue added in v0.2.0

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

func (*DynamicParameterContext) GetRawValue added in v0.2.0

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

func (*DynamicParameterContext) GetValue added in v0.2.0

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

type DynamicParameters added in v0.2.0

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 added in v0.1.7

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 added in v0.1.7

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 added in v0.1.7

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

func NewJsonRecordWithAttrNamesText added in v0.1.7

func NewJsonRecordWithAttrNamesText(columns []*Column) *JsonRecordWithAttrNames

func (*JsonRecordWithAttrNames) Clean added in v0.1.7

func (rr *JsonRecordWithAttrNames) Clean()

func (*JsonRecordWithAttrNames) Decode added in v0.1.7

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

func (*JsonRecordWithAttrNames) Encode added in v0.1.7

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

func (*JsonRecordWithAttrNames) GetColumn added in v0.1.7

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

func (*JsonRecordWithAttrNames) Length added in v0.1.7

func (rr *JsonRecordWithAttrNames) Length() int

func (*JsonRecordWithAttrNames) MarshalJSON added in v0.1.7

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

func (*JsonRecordWithAttrNames) SetColumn added in v0.1.7

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

func (*JsonRecordWithAttrNames) UnmarshalJSON added in v0.1.7

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

type JsonRecordWithAttrNamesBinary added in v0.1.7

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

func NewJsonRecordWithAttrNamesBinary added in v0.1.7

func NewJsonRecordWithAttrNamesBinary(columns []*Column) *JsonRecordWithAttrNamesBinary

func (*JsonRecordWithAttrNamesBinary) Clean added in v0.1.7

func (rr *JsonRecordWithAttrNamesBinary) Clean()

func (*JsonRecordWithAttrNamesBinary) Decode added in v0.1.7

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

func (*JsonRecordWithAttrNamesBinary) Encode added in v0.1.7

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

func (*JsonRecordWithAttrNamesBinary) GetColumn added in v0.1.7

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

func (*JsonRecordWithAttrNamesBinary) Length added in v0.1.7

func (rr *JsonRecordWithAttrNamesBinary) Length() int

func (*JsonRecordWithAttrNamesBinary) MarshalJSON added in v0.1.7

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

func (*JsonRecordWithAttrNamesBinary) SetColumn added in v0.1.7

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

func (*JsonRecordWithAttrNamesBinary) UnmarshalJSON added in v0.1.7

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 added in v0.2.0

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

type Oid

type Oid int

type ParameterDefinition added in v0.2.0

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 added in v0.2.0

func MustNewParameterDefinition(name string, description string) *ParameterDefinition

func NewParameterDefinition added in v0.2.0

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

func (*ParameterDefinition) SetAllowedValues added in v0.2.0

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

func (*ParameterDefinition) SetCastDbType added in v0.2.0

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

func (*ParameterDefinition) SetDefaultValue added in v0.2.0

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

func (*ParameterDefinition) SetDynamicMode added in v0.2.0

func (*ParameterDefinition) SetGetFromGlobalEnvVariable added in v0.2.0

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

func (*ParameterDefinition) SetIsColumn added in v0.2.0

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

func (*ParameterDefinition) SetIsColumnContainer added in v0.2.0

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

func (*ParameterDefinition) SetLinkParameter added in v0.2.0

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

func (*ParameterDefinition) SetRawValueValidator added in v0.2.0

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

func (*ParameterDefinition) SetRequired added in v0.2.0

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

func (*ParameterDefinition) SetSupportTemplate added in v0.2.0

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

func (*ParameterDefinition) SetUnmarshaler added in v0.2.0

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

type ParameterValuer added in v0.2.0

type ParameterValuer interface {
	Value()
}

type Parameterizer added in v0.2.0

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 added in v0.2.0

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

type ParamsValue

type ParamsValue []byte

func (*ParamsValue) ParameterValuer added in v0.2.0

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 added in v0.1.7

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 added in v0.1.7

type RawRecordAttrs map[string]*RawValue

type RawRecordAttrsText added in v0.1.7

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 added in v0.2.0

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

func NewRecordContext added in v0.2.0

func NewRecordContext() *RecordContext

func (*RecordContext) Clean added in v0.2.0

func (rc *RecordContext) Clean()

func (*RecordContext) DecodeValueByColumn added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

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

func (*RecordContext) GetColumnRawValue added in v0.2.1

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

func (*RecordContext) GetColumnType added in v0.2.0

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

func (*RecordContext) GetColumnValue added in v0.2.0

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

func (*RecordContext) SetColumnRawValue added in v0.2.1

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

func (*RecordContext) SetColumnValue added in v0.2.0

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

func (*RecordContext) SetRecord added in v0.2.0

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

type Reference added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

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

func (*StaticParameter) GetDefinition added in v0.2.0

func (sp *StaticParameter) GetDefinition() *ParameterDefinition

func (*StaticParameter) Init added in v0.2.0

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

func (*StaticParameter) IsDynamic added in v0.2.0

func (sp *StaticParameter) IsDynamic() bool

func (*StaticParameter) IsEmpty added in v0.2.0

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

func (*StaticParameter) RawValue added in v0.2.0

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

func (*StaticParameter) Scan added in v0.2.0

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

func (*StaticParameter) Value added in v0.2.0

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

type StaticParameterContext added in v0.2.0

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

func NewStaticParameterContext added in v0.2.0

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

func (*StaticParameterContext) DecodeValue added in v0.2.0

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

func (*StaticParameterContext) DecodeValueByColumn added in v0.2.0

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

func (*StaticParameterContext) DecodeValueByType added in v0.2.0

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

func (*StaticParameterContext) EncodeValue added in v0.2.0

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

func (*StaticParameterContext) EncodeValueByColumn added in v0.2.0

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

func (*StaticParameterContext) EncodeValueByType added in v0.2.0

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

func (*StaticParameterContext) GetColumnType added in v0.2.0

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

type StaticParameters added in v0.2.0

type StaticParameters map[string]ParamsValue

func (*StaticParameters) MarshalJSON added in v0.2.0

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"`
	Constraints []Constraint `json:"-"`
}

func (*Table) Validate

func (t *Table) Validate() error

type TestRowDriver added in v0.2.1

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

func (*TestRowDriver) Clean added in v0.2.1

func (trd *TestRowDriver) Clean()

func (*TestRowDriver) Decode added in v0.2.1

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

func (*TestRowDriver) Encode added in v0.2.1

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

func (*TestRowDriver) GetColumn added in v0.2.1

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

func (*TestRowDriver) Length added in v0.2.1

func (trd *TestRowDriver) Length() int

func (*TestRowDriver) SetColumn added in v0.2.1

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 added in v0.2.0

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 added in v0.2.0

func NewTransformerDefinition(name string, makeFunc NewTransformerFunc) *TransformerDefinition

func (*TransformerDefinition) AddParameter added in v0.2.0

func (*TransformerDefinition) SetDescription added in v0.2.0

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

func (*TransformerDefinition) SetExpectedExitCode added in v0.2.0

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

func (*TransformerDefinition) SetMode added in v0.2.0

func (*TransformerDefinition) SetValidate added in v0.2.0

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 added in v0.1.7

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 added in v0.2.0

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

func (*Type) IsAffected

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

type TypeCastDefinition added in v0.2.0

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

func (*TypeCastDefinition) ValidateTypes added in v0.2.0

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

type TypeCastFunc added in v0.2.0

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

TypeCastFunc the function implements type casting from one to another

type TypeCaster added in v0.2.0

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

func (*TypeCaster) Cast added in v0.2.0

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 added in v0.1.7

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 added in v0.2.1

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 added in v0.2.1

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