psql

package
v1.1.163 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: GPL-3.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ROUTINE_TYPE_PROC = "PROCEDURE"
	ROUTINE_TYPE_FUNC = "FUNCTION"
)

ROUTINE_TYPE_PROC & ROUTINE_TYPE_FUNC are named POsqgreSQL routine

Variables

View Source
var (
	ErrUnknownType               = errors.New("Can't define unknown type!")
	ErrUnknownRoutineType        = errors.New("Can't add routine unknown type!")
	ErrFunctionWithoutResultType = errors.New("Can't add function without results type!")
)

ErrUnknownRoutineType, ErrFunctionWithoutResultType are some errors

Functions

func GetArrayByteFromByte added in v1.1.45

func GetArrayByteFromByte(ci *pgtype.ConnInfo, src []byte, name string) (dto sql.RawBytes)

GetArrayByteFromByte convert data from src into sql.RawBytes

func GetArrayFloat32FromByte added in v1.1.45

func GetArrayFloat32FromByte(ci *pgtype.ConnInfo, src []byte, name string) []float32

GetFloat32FromByte convert data from src into float32

func GetArrayFloat64FromByte added in v1.1.45

func GetArrayFloat64FromByte(ci *pgtype.ConnInfo, src []byte, name string) []float64

GetFloat64FromByte convert data from src into float64

func GetArrayInt16FromByte added in v1.1.26

func GetArrayInt16FromByte(ci *pgtype.ConnInfo, src []byte, name string) []int16

GetArrayInt16FromByte convert data from src into []int16

func GetArrayInt32FromByte added in v1.1.26

func GetArrayInt32FromByte(ci *pgtype.ConnInfo, src []byte, name string) []int32

GetArrayInt32FromByte convert data from src into []int32

func GetArrayInt64FromByte added in v1.1.26

func GetArrayInt64FromByte(ci *pgtype.ConnInfo, src []byte, name string) []int64

GetArrayInt64FromByte convert data from src into []int64

func GetArrayRefTimeFromByte added in v1.1.45

func GetArrayRefTimeFromByte(ci *pgtype.ConnInfo, src []byte, name string) []*time.Time

GetArrayTimeFromByte convert data from src into []time.Time

func GetArrayStringFromByte added in v1.1.36

func GetArrayStringFromByte(ci *pgtype.ConnInfo, src []byte, name string) []string

GetArrayStringFromByte convert data from src into []string

func GetArrayTimeFromByte added in v1.1.11

func GetArrayTimeFromByte(ci *pgtype.ConnInfo, src []byte, name string) []time.Time

GetArrayTimeFromByte convert data from src into []time.Time

func GetArrayTimeTimeFromByte added in v1.1.45

func GetArrayTimeTimeFromByte(ci *pgtype.ConnInfo, src []byte, name string) []time.Time

GetArrayTimeTimeFromByte convert data from src into []time.Time (alias for GetArrayTimeFromByte)

func GetBoolFromByte added in v1.1.11

func GetBoolFromByte(ci *pgtype.ConnInfo, src []byte, name string) bool

GetBoolFromByte convert data from src into bool

func GetDateFromByte added in v1.1.9

func GetDateFromByte(src []byte, name string) time.Time

GetDateFromByte convert date from src into time.Tome

func GetFloat32FromByte added in v1.1.45

func GetFloat32FromByte(ci *pgtype.ConnInfo, src []byte, name string) float32

GetFloat32FromByte convert data from src into float32

func GetFloat64FromByte added in v1.1.9

func GetFloat64FromByte(ci *pgtype.ConnInfo, src []byte, name string) float64

GetFloat64FromByte convert data from src into float64

func GetInetFromByte added in v1.1.11

func GetInetFromByte(ci *pgtype.ConnInfo, src []byte, name string) pgtype.Inet

GetInetFromByte convert data from src into pgtype.Inet

func GetInt16FromByte added in v1.1.9

func GetInt16FromByte(ci *pgtype.ConnInfo, src []byte, name string) int16

GetInt16FromByte convert data from src into int16

func GetInt32FromByte added in v1.1.9

func GetInt32FromByte(ci *pgtype.ConnInfo, src []byte, name string) int32

GetInt32FromByte convert data from src into int32

func GetInt64FromByte added in v1.1.9

func GetInt64FromByte(ci *pgtype.ConnInfo, src []byte, name string) int64

GetInt64FromByte convert data from src into int64

func GetIntervalFromByte added in v1.1.19

func GetIntervalFromByte(ci *pgtype.ConnInfo, src []byte, name string) (dto pgtype.Interval)

GetIntervalFromByte convert data from src into []time.Time

func GetJsonFromByte added in v1.1.11

func GetJsonFromByte(ci *pgtype.ConnInfo, src []byte, name string) interface{}

GetJsonFromByte convert data from src into json

func GetRawBytesFromByte added in v1.1.41

func GetRawBytesFromByte(ci *pgtype.ConnInfo, src []byte, name string) (dto sql.RawBytes)

GetRawBytesFromByte convert data from src into sql.RawBytes

func GetRefTimeFromByte added in v1.1.11

func GetRefTimeFromByte(ci *pgtype.ConnInfo, src []byte, name string) *time.Time

GetRefTimeFromByte convert data from src into *time.Time

func GetScanner added in v1.1.45

func GetScanner[T sql.Scanner](ci *pgtype.ConnInfo, src []byte, name string, dto T) T

GetInt32FromByte convert data from src into int32

func GetSqlNullInt32FromByte added in v1.1.45

func GetSqlNullInt32FromByte(ci *pgtype.ConnInfo, src []byte, name string) sql.NullInt32

GetInt32FromByte convert data from src into int32

func GetSqlNullStringFromByte added in v1.1.45

func GetSqlNullStringFromByte(ci *pgtype.ConnInfo, src []byte, name string) sql.NullString

GetStringFromByte convert data (As Text!) from src into string

func GetStringFromByte added in v1.1.11

func GetStringFromByte(ci *pgtype.ConnInfo, src []byte, name string) string

GetStringFromByte convert data (As Text!) from src into string

func GetTextDecoder added in v1.1.45

func GetTextDecoder[T pgtype.TextDecoder](ci *pgtype.ConnInfo, src []byte, name string, dto T) T

func GetTimeFromByte added in v1.1.11

func GetTimeFromByte(ci *pgtype.ConnInfo, src []byte, name string) time.Time

GetTimeFromByte convert data from src into time.Time

func GetTimeTimeFromByte added in v1.1.45

func GetTimeTimeFromByte(ci *pgtype.ConnInfo, src []byte, name string) time.Time

GetTimeTimeFromByte convert data from src into *time.Time (alias for GetTimeFromByte)

func SetLogLevel added in v1.0.1089

func SetLogLevel(lvl string) pgx.LogLevel

SetLogLevel set logs level DB operations

func TrimQuotes added in v1.1.11

func TrimQuotes(src []byte) string

func UdtNameToType added in v1.1.7

func UdtNameToType(udtName string) types.BasicKind

UdtNameToType return types.BasicKind according to psql udtName

Types

type BuildConnOptions added in v1.1.53

type BuildConnOptions func(route *Conn)

BuildRouteOptions implement 'Functional Option' pattern for ApiRoute settings

func AfterConnect added in v1.1.53

func AfterConnect(fnc FncConn) BuildConnOptions

AfterConnect set custom AfterConnect method on ApiRoute

func BeforeAcquire added in v1.1.53

func BeforeAcquire(fnc FncAcqu) BuildConnOptions

BeforeAcquire set same custom method on ApiRoute

func ChannelHandler added in v1.1.53

func ChannelHandler(fnc pgconn.NotificationHandler) BuildConnOptions

ChannelHandler set same custom method on ApiRoute

func Channels added in v1.1.53

func Channels(channels ...string) BuildConnOptions

NoticeHandler set same custom method on ApiRoute

func NoticeHandler added in v1.1.53

func NoticeHandler(fnc pgconn.NoticeHandler) BuildConnOptions

NoticeHandler set same custom method on ApiRoute

type Column

type Column struct {
	DataType string

	CharacterSetName string

	UdtName string

	PrimaryKey  bool
	Constraints map[string]*dbEngine.ForeignKey
	IsHidden    bool
	Position    int32
	UserDefined *dbEngine.Types
	// contains filtered or unexported fields
}

Column implement store data of column of table

func NewColumn

func NewColumn(
	table *Table,
	name string,
	dataType string,
	colDefault any,
	isNullable bool,
	characterSetName string,
	comment string,
	udtName string,
	characterMaximumLength int,
	primaryKey bool,
	isHidden bool,
) *Column

NewColumn create new column with many properties

func NewColumnForTableBuf added in v1.0.1141

func NewColumnForTableBuf(table *Table) *Column

NewColumnForTableBuf create Column for scanning operation of Table

func NewColumnPone

func NewColumnPone(name string, comment string, characterMaximumLength int) *Column

NewColumnPone create new column with several properties

func (*Column) AutoIncrement

func (col *Column) AutoIncrement() bool

AutoIncrement return true if column is autoincrement

func (*Column) BasicType

func (col *Column) BasicType() types.BasicKind

BasicType return golang type of column

func (*Column) BasicTypeInfo

func (col *Column) BasicTypeInfo() types.BasicInfo

BasicTypeInfo of columns value

func (*Column) CharacterMaximumLength

func (col *Column) CharacterMaximumLength() int

CharacterMaximumLength return max of length text columns

func (*Column) CheckAttr

func (col *Column) CheckAttr(colDefine string) (flags []dbEngine.FlagColumn)

CheckAttr check attributes of column on DB schema according to ddl-file

func (*Column) Comment

func (col *Column) Comment() string

Comment of column

func (*Column) Copy added in v1.0.1141

func (col *Column) Copy() *Column

Copy column & return new instance

func (*Column) Default

func (col *Column) Default() any

Default return default value of column

func (*Column) Foreign added in v1.0.1141

func (col *Column) Foreign() *dbEngine.ForeignKey

Foreign return first foreign key of column

func (*Column) GetFields

func (col *Column) GetFields(columns []dbEngine.Column) []any

GetFields implement RowColumn interface

func (*Column) IsArray added in v1.1.49

func (col *Column) IsArray() bool

IsArray of column (psql native)

func (*Column) IsNullable

func (col *Column) IsNullable() bool

IsNullable return isNullable flag

func (*Column) Name

func (col *Column) Name() string

Name of column

func (*Column) Primary

func (col *Column) Primary() bool

Primary return true if column is primary key

func (*Column) RefColValue added in v1.0.1141

func (col *Column) RefColValue(name string) any

RefColValue referral of column property 'name'

func (*Column) Required

func (col *Column) Required() bool

Required return true if column need a value

func (*Column) SetDefault added in v1.0.1060

func (col *Column) SetDefault(d any)

SetDefault set default value into column

func (*Column) SetNullable

func (col *Column) SetNullable(f bool)

SetNullable set nullable flag of column

func (*Column) Table

func (col *Column) Table() dbEngine.Table

Table implement dbEngine.Column interface return table of column

func (*Column) Type

func (col *Column) Type() string

Type of column (psql native)

func (*Column) UserDefinedType added in v1.1.41

func (col *Column) UserDefinedType() *dbEngine.Types

UserDefinedType return define type

type Conn

type Conn struct {
	*pgxpool.Pool
	*pgxpool.Config
	AfterConnect   FncConn
	BeforeAcquire  FncAcqu
	ChannelHandler pgconn.NotificationHandler
	NoticeHandler  pgconn.NoticeHandler
	NoticeMap      map[uint32]*pgconn.Notice

	Cancel context.CancelFunc
	// contains filtered or unexported fields
}

Conn implement connection to DB over pgx

func NewConn

func NewConn(afterConnect FncConn, beforeAcquire FncAcqu, noticeHandler pgconn.NoticeHandler, channels ...string) *Conn

NewConn create new instance

func NewConnWithOptions added in v1.1.53

func NewConnWithOptions(options ...BuildConnOptions) *Conn

NewConnWithOptions create new instance

func (*Conn) ExecDDL

func (c *Conn) ExecDDL(ctx context.Context, sql string, args ...any) error

ExecDDL execute sql

func (*Conn) GetNotice

func (c *Conn) GetNotice(conn *pgxpool.Conn) (n *pgconn.Notice, ok bool)

GetNotice return last notice of conn

func (*Conn) GetRoutines added in v1.0.1025

func (c *Conn) GetRoutines(ctx context.Context, dbTypes map[string]dbEngine.Types, tables map[string]dbEngine.Table, cfg *dbEngine.CfgDB) (routines map[string]dbEngine.Routine, err error)

GetRoutines get properties of DB routines & returns them as map

func (*Conn) GetSchema

func (c *Conn) GetSchema(ctx context.Context, cfg *dbEngine.CfgDB) (map[string]*string, map[string]dbEngine.Table, map[string]dbEngine.Routine, map[string]dbEngine.Types, error)

GetSchema read DB schema & store it

func (*Conn) GetStat

func (c *Conn) GetStat() string

GetStat return stats of Pool

func (*Conn) GetTablesProp

func (c *Conn) GetTablesProp(ctx context.Context, dbTypes map[string]dbEngine.Types, cfg *dbEngine.CfgDB) (map[string]dbEngine.Table, error)

GetTablesProp populate tables schemas data

func (*Conn) InitConn

func (c *Conn) InitConn(ctx context.Context, dbURL string) error

InitConn create pool of connection

func (*Conn) LastRowAffected added in v1.0.1092

func (c *Conn) LastRowAffected() int64

LastRowAffected return number of insert/deleted/updated rows

func (*Conn) NewTable

func (c *Conn) NewTable(name, typ string) dbEngine.Table

NewTable create new empty Table with name & type

func (*Conn) NewTableWithCheck added in v1.1.15

func (c *Conn) NewTableWithCheck(ctx context.Context, name string) (*Table, error)

NewTableWithCheck create new Table with name, check the table from schema, populate columns and indexes

func (*Conn) SelectAndPerformRaw added in v1.0.1146

func (c *Conn) SelectAndPerformRaw(ctx context.Context, each dbEngine.FncRawRow, sql string, args ...any) error

SelectAndPerformRaw run sql with args & run each every row

func (*Conn) SelectAndRunEach

func (c *Conn) SelectAndRunEach(ctx context.Context, each dbEngine.FncEachRow, sql string, args ...any) error

SelectAndRunEach run sql with args and performs each every row of query results

func (*Conn) SelectAndScanEach

func (c *Conn) SelectAndScanEach(ctx context.Context, each func() error, rowValue dbEngine.RowScanner,
	sql string, args ...any) error

SelectAndScanEach run sql with args return every row into rowValues & run each

func (*Conn) SelectOneAndScan added in v1.0.1038

func (c *Conn) SelectOneAndScan(ctx context.Context, rowValues any, sql string, args ...any) (err error)

SelectOneAndScan run sql with args return rows into rowValues

func (*Conn) SelectToMap added in v1.0.1038

func (c *Conn) SelectToMap(ctx context.Context, sql string, args ...any) (map[string]any, error)

SelectToMap run sql with args return rows as map[{name_column}] case of executed - gets one record

func (*Conn) SelectToMaps added in v1.0.1038

func (c *Conn) SelectToMaps(ctx context.Context, sql string, args ...any) ([]map[string]any, error)

SelectToMaps run sql with args return rows as slice of map[{name_column}]

func (*Conn) SelectToMultiDimension added in v1.0.1038

func (c *Conn) SelectToMultiDimension(ctx context.Context, sql string, args ...any) (
	rows [][]any, cols []dbEngine.Column, err error)

SelectToMultiDimension run sql with args and return rows (slice of record) and columns

func (*Conn) StartChannels

func (c *Conn) StartChannels()

StartChannels starts listeners of PSQL channels according to list of channels

type FncAcqu added in v1.1.53

type FncAcqu func(context.Context, *pgx.Conn) bool

type FncConn added in v1.1.53

type FncConn func(context.Context, *pgx.Conn) error

type Numeric added in v1.0.1151

type Numeric struct {
	*pgtype.Numeric
}

Numeric expanded pgtype.Numeric

func GetNumericFromByte added in v1.1.11

func GetNumericFromByte(ci *pgtype.ConnInfo, src []byte, name string) Numeric

GetNumericFromByte convert data from src into Numeric

func NewNumericFromBytes added in v1.0.11562

func NewNumericFromBytes(value []byte) (*Numeric, error)

NewNumericFromBytes create Numeric from bytes

func NewNumericFromFloat64 added in v1.0.1155

func NewNumericFromFloat64(value float64) Numeric

NewNumericFromFloat64 create Numeric with float value

func NewNumericNull added in v1.0.1151

func NewNumericNull() Numeric

NewNumericNull create Numeric with NULL

func (*Numeric) AssignTo added in v1.0.1151

func (src *Numeric) AssignTo(dst interface{}) error

AssignTo has performing []byte dst

func (*Numeric) DecodeBinary added in v1.0.1151

func (dst *Numeric) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error

DecodeBinary expand pgtype.Numeric.DecodeBinary

func (*Numeric) DecodeText added in v1.0.1151

func (dst *Numeric) DecodeText(ci *pgtype.ConnInfo, src []byte) error

DecodeText expand pgtype.Numeric.DecodeText()

func (Numeric) EncodeText added in v1.0.11561

func (src Numeric) EncodeText(ci *pgtype.ConnInfo, buf []byte) ([]byte, error)

EncodeText expand pgtype.Numeric.EncodeText()

func (*Numeric) Float64 added in v1.1.21

func (src *Numeric) Float64() float64

func (*Numeric) Set added in v1.0.1151

func (dst *Numeric) Set(src interface{}) error

Set has performing []byte src

type PgxRoutineParams

type PgxRoutineParams struct {
	Column
	Fnc      *Routine `json:"-"`
	Position int32
}

PgxRoutineParams consist data of DB routines param

type Routine

type Routine struct {
	ID      int
	Comment string

	Type string

	DataType string
	UdtName  string
	// contains filtered or unexported fields
}

Routine consist data of DB routine and operation for reading it and perform query

func (*Routine) BuildSql added in v1.0.1093

func (r *Routine) BuildSql(Options ...dbEngine.BuildSqlOptions) (string, []any, error)

BuildSql create sql query & arg for call conn.Select...

func (*Routine) Call

func (r *Routine) Call(ctx context.Context, args ...any) error

Call procedure

func (*Routine) Columns added in v1.0.1030

func (r *Routine) Columns() []dbEngine.Column

Columns of Routine

func (*Routine) GetFields added in v1.0.1103

func (r *Routine) GetFields(columns []dbEngine.Column) []any

GetFields implements interface RowScanner

func (*Routine) GetParams

func (r *Routine) GetParams(ctx context.Context, types map[string]dbEngine.Types, tables map[string]dbEngine.Table) error

GetParams requests parameters of routine & split them according to IN/OUT

func (*Routine) Name

func (r *Routine) Name() string

Name of Routine

func (*Routine) Overlay

func (r *Routine) Overlay() dbEngine.Routine

Overlay return routine with some name if exists

func (*Routine) Params

func (r *Routine) Params() []dbEngine.Column

Params of routine

func (*Routine) ReturnType added in v1.0.1147

func (r *Routine) ReturnType() string

ReturnType get type of routine result

func (*Routine) Select

func (r *Routine) Select(ctx context.Context, args ...any) error

Select run sql with Options (deprecated)

func (*Routine) SelectAndRunEach added in v1.0.1027

func (r *Routine) SelectAndRunEach(ctx context.Context, each dbEngine.FncEachRow, Options ...dbEngine.BuildSqlOptions) error

SelectAndRunEach run sql of table with Options & performs each every row of query results

func (*Routine) SelectAndScanEach added in v1.0.1027

func (r *Routine) SelectAndScanEach(ctx context.Context, each func() error, row dbEngine.RowScanner, Options ...dbEngine.BuildSqlOptions) error

SelectAndScanEach run sql of table with Options & return every row into rowValues & run each

func (*Routine) SelectOneAndScan added in v1.0.1103

func (r *Routine) SelectOneAndScan(ctx context.Context, row any, Options ...dbEngine.BuildSqlOptions) error

SelectOneAndScan run sqlof table with Options & return rows into rowValues

type Table

type Table struct {
	Type string
	ID   int

	PK string
	// contains filtered or unexported fields
}

Table implement dbEngine interface Table for PostgreSQL

func (*Table) Columns

func (t *Table) Columns() []dbEngine.Column

Columns of Table

func (*Table) Comment

func (t *Table) Comment() string

Comment of Table

func (*Table) Delete added in v1.0.1134

func (t *Table) Delete(ctx context.Context, Options ...dbEngine.BuildSqlOptions) (int64, error)

Delete row of table according to Options

func (*Table) DoCopy added in v1.0.1151

func (t *Table) DoCopy(ctx context.Context, src pgx.CopyFromSource, columns ...string) (int64, error)

DoCopy run CopyFrom PSQL use src interface

func (*Table) FindColumn

func (t *Table) FindColumn(name string) dbEngine.Column

FindColumn return column 'name' on Table or nil

func (*Table) FindIndex

func (t *Table) FindIndex(name string) *dbEngine.Index

FindIndex get index according to name

func (*Table) GetColumns

func (t *Table) GetColumns(ctx context.Context, dbTypes map[string]dbEngine.Types) error

GetColumns получение значений полей для форматирования данных получение значений полей для таблицы

func (*Table) GetFields

func (t *Table) GetFields(columns []dbEngine.Column) []any

GetFields implement RowScanner interface

func (*Table) GetIndexes added in v1.0.1095

func (t *Table) GetIndexes(ctx context.Context) error

GetIndexes collect index of table

func (*Table) Indexes added in v1.0.1113

func (t *Table) Indexes() dbEngine.Indexes

Indexes get indexex according to table

func (*Table) Insert

func (t *Table) Insert(ctx context.Context, Options ...dbEngine.BuildSqlOptions) (int64, error)

Insert new row & return new ID or rowsAffected if there not autoinc field

func (*Table) Name

func (t *Table) Name() string

Name of Table

func (*Table) ReReadColumn added in v1.0.1040

func (t *Table) ReReadColumn(ctx context.Context, name string) dbEngine.Column

ReReadColumn renew properties of column 'name'

func (*Table) Select

func (t *Table) Select(ctx context.Context, Options ...dbEngine.BuildSqlOptions) error

Select run sql with Options (deprecated)

func (*Table) SelectAndRunEach

func (t *Table) SelectAndRunEach(ctx context.Context, each dbEngine.FncEachRow, Options ...dbEngine.BuildSqlOptions) error

SelectAndRunEach run sql of table with Options & performs each every row of query results

func (*Table) SelectAndScanEach

func (t *Table) SelectAndScanEach(ctx context.Context, each func() error, row dbEngine.RowScanner, Options ...dbEngine.BuildSqlOptions) error

SelectAndScanEach run sql of table with Options & return every row into rowValues & run each

func (*Table) SelectOneAndScan added in v1.0.1088

func (t *Table) SelectOneAndScan(ctx context.Context, row any, Options ...dbEngine.BuildSqlOptions) error

SelectOneAndScan run sqlof table with Options & return rows into rowValues

func (*Table) Update

func (t *Table) Update(ctx context.Context, Options ...dbEngine.BuildSqlOptions) (int64, error)

Update table according to Options

func (*Table) Upsert

func (t *Table) Upsert(ctx context.Context, Options ...dbEngine.BuildSqlOptions) (int64, error)

Upsert preforms INSERT sql or UPDATE if record with primary keys exists

Jump to

Keyboard shortcuts

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