toolkit

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 24 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 (
	ErrorValidationSeverity   = "error"
	WarningValidationSeverity = "warning"
	InfoValidationSeverity    = "info"
	DebugValidationSeverity   = "debug"
)
View Source
const WithoutMaxLength = -1

Variables

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 GetAffectedAndTransferringColumns

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

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 *Definition) *Cmd

type Column

type Column struct {
	Name        string `json:"name"`
	TypeName    string `json:"type_name"`
	TypeOid     Oid    `json:"type_oid"`
	Num         AttNum `json:"num"`
	NotNull     bool   `json:"not_null"`
	Length      int    `json:"length"`
	Idx         int    `json:"idx"`
	IsGenerated bool   `json:"is_generated"`
}

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 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 Definition

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

func NewDefinition

func NewDefinition(name string, makeFunc NewTransformerFunc) *Definition

func (*Definition) AddParameter

func (d *Definition) AddParameter(v *Parameter) *Definition

func (*Definition) SetDescription

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

func (*Definition) SetExpectedExitCode

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

func (*Definition) SetMode

func (d *Definition) SetMode(v *DriverParams) *Definition

func (*Definition) SetValidate

func (d *Definition) SetValidate(v bool) *Definition

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 NewDriver

func NewDriver(table *Table, customTypes []*Type, columnTypeOverrides map[string]string) (*Driver, error)

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) 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 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          Params            `json:"parameters"`
	Types               []*Type           `json:"types"`
	ColumnTypeOverrides map[string]string `json:"column_type_overrides"`
}

type NewRowDriverFunc

type NewRowDriverFunc func() RowDriver

type NewTransformerFunc

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

type Oid

type Oid int

type Parameter

type Parameter 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"`
	// LinkParameter - 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
	LinkParameter string `mapstructure:"link_parameter" json:"link_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"`
	// DefaultValue - default value of the parameter. Must be variable pointer and have the same type
	// as in ExpectedType
	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"`
	// 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"`
	// 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:"-"`
	// LinkedParameter - column-like parameter that has been linked during parsing procedure. Warning, do not
	// assign it manually, if you don't know the consequences
	LinkedColumnParameter *Parameter `json:"-"`
	// 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 `json:"-"`
	// ExpectedType - expected type of the provided variable during scanning procedure. It must be pointer on the
	// variable
	Driver *Driver `mapstructure:"-" json:"-"`
	// contains filtered or unexported fields
}

Parameter - 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 Definition of the transformer if transformer has any parameters

func MustNewParameter

func MustNewParameter(name string, description string) *Parameter

func NewParameter

func NewParameter(name string, description string) (*Parameter, error)

func (*Parameter) Copy

func (p *Parameter) Copy() *Parameter

func (*Parameter) Init

func (p *Parameter) Init(driver *Driver, types []*Type, params []*Parameter, rawValue ParamsValue) (ValidationWarnings, error)

func (*Parameter) RawValue

func (p *Parameter) RawValue() ParamsValue

func (*Parameter) Scan

func (p *Parameter) Scan(dest any) (empty bool, err error)

Scan - scan parsed value into received pointer. Param src must be pointer

func (*Parameter) SetCastDbType

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

func (*Parameter) SetDefaultValue

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

func (*Parameter) SetGetFromGlobalEnvVariable added in v0.1.7

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

func (*Parameter) SetIsColumn

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

func (*Parameter) SetIsColumnContainer added in v0.1.6

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

func (*Parameter) SetLinkParameter

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

func (*Parameter) SetRawValueValidator

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

func (*Parameter) SetRequired

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

func (*Parameter) SetUnmarshaller

func (p *Parameter) SetUnmarshaller(unmarshaller Unmarshaller) *Parameter

func (*Parameter) Value

func (p *Parameter) Value() (any, error)

Value - returns parsed value that later might be cast via type assertion or so on

type Params

type Params map[string]ParamsValue

func (*Params) MarshalJSON

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

type ParamsValue

type ParamsValue []byte

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

func (*Table) Validate

func (t *Table) Validate() 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 Trace

type Trace struct {
	SchemaName      string `json:"schemaName,omitempty"`
	TableName       string `json:"tableName,omitempty"`
	TransformerName string `json:"transformerName,omitempty"`
	ParameterName   string `json:"parameterName,omitempty"`
	Msg             string `json:"msg,omitempty"`
}

deprecated

type Transformer

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

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"`
	// Chain - list of inherited types till the main base type
	Chain []Oid `json:"chain,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"`
	// RootBuiltInType - defines builtin type oid that might be used for decoding and encoding
	RootBuiltInType Oid `json:"root_built_in_type,omitempty"`
}

Type - describes pg_catalog.pg_type

func (*Type) IsAffected

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

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 *Parameter, driver *Driver, src ParamsValue) (any, error)

type ValidationWarning

type ValidationWarning struct {
	Msg      string         `json:"msg,omitempty"`
	Severity string         `json:"severity,omitempty"`
	Trace    *Trace         `json:"trace,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

func (*ValidationWarning) SetTrace

func (re *ValidationWarning) SetTrace(value *Trace) *ValidationWarning

type ValidationWarnings

type ValidationWarnings []*ValidationWarning

func InitParameters

func InitParameters(
	driver *Driver, rawParams map[string]ParamsValue, paramDef []*Parameter, types []*Type,
) (map[string]*Parameter, 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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