Documentation
¶
Overview ¶
Package pgq - generating PostgreSql queries using a template
Index ¶
- func Bind(template string, variable string, value interface{}, key string) (string, error)
- type Query
- func (q *Query) Bool(field string) bool
- func (q *Query) Bytes(field string) []byte
- func (q *Query) Close()
- func (t *Query) Connection() *pgx.Conn
- func (q *Query) Contains(field string) bool
- func (t *Query) Context() context.Context
- func (q *Query) Duration(field string) time.Duration
- func (q *Query) Exec(sql string) error
- func (q *Query) ExecBind(sqlTemplate string, values map[string]interface{}, key string) error
- func (q *Query) ExecBindCon(sqlTemplate string, c dcon.ContainerReader, values map[string]dcon.PropertyID, ...) error
- func (q *Query) FieldName(index int) string
- func (q *Query) FieldType(name string) uint32
- func (q *Query) FieldTypeIndex(index int) uint32
- func (q *Query) FieldTypeName(name string) string
- func (q *Query) FieldTypeNameIndex(index int) string
- func (q *Query) Fields() []pgproto3.FieldDescription
- func (q *Query) Float32(field string) float32
- func (q *Query) Float64(field string) float64
- func (q *Query) Int(field string) int
- func (q *Query) Int64(field string) int64
- func (q *Query) IsCommand() bool
- func (q *Query) IsSelect() bool
- func (q *Query) LoadLargeObject(transaction pgx.Tx, oid uint32) ([]byte, error)
- func (q *Query) Next() bool
- func (t *Query) Pool() *pgxpool.Pool
- func (q *Query) RemoveLargeObject(transaction pgx.Tx, oid uint32) error
- func (q *Query) RowsAffected() int64
- func (q *Query) SaveLargeObject(transaction pgx.Tx, oid uint32, data []byte) (uint32, error)
- func (q *Query) Select(sql string) error
- func (q *Query) SelectBind(sqlTemplate string, values map[string]interface{}, key string) error
- func (q *Query) SelectBindCon(sqlTemplate string, c dcon.ContainerReader, values map[string]dcon.PropertyID, ...) error
- func (q *Query) String(field string) string
- func (q *Query) Time(field string) time.Time
- func (q *Query) Value(field string) interface{}
- func (q *Query) ValueIndex(fieldIndex int) interface{}
- type SqlBinder
- func (b *SqlBinder) Bind(variable string, value interface{}) error
- func (b *SqlBinder) BindCon(c dcon.ContainerReader, values map[string]dcon.PropertyID) error
- func (b *SqlBinder) BindValues(values map[string]interface{}) error
- func (b *SqlBinder) Clear()
- func (b *SqlBinder) IsVariableParsed(v string) bool
- func (b *SqlBinder) ParcedVariables() []string
- func (b *SqlBinder) Sql() (string, error)
- type SqlBinderParser
- type TxNested
- func (t *TxNested) Begin() (pgx.Tx, error)
- func (t *TxNested) Commit() error
- func (t *TxNested) Connection() *pgx.Conn
- func (t *TxNested) Context() context.Context
- func (t *TxNested) Level() int
- func (t *TxNested) Pool() *pgxpool.Conn
- func (t *TxNested) Rollback() error
- func (t *TxNested) Tx() pgx.Tx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query - wrapper for pgx Query/Exec
func NewQueryPool ¶
NewQueryPool - create a Query based on pgxpool.Conn
func (*Query) Bool ¶
Int64 - field value by name, converted to int64 (only for Select and after a successful Next call)
func (*Query) Bytes ¶
Bytes - field value by name, converted to []byte (only for Select and after a successful Next call)
func (*Query) Close ¶
func (q *Query) Close()
Close - close the selection. Use for Select in case we don't get to the end of Next
func (*Query) Duration ¶
Duration - field value by name, converted to time.Duration (only for Select and after a successful Next call)
func (*Query) ExecBind ¶
ExecBind - execution of the insert, update, delete command with the substitution of values in the template
func (*Query) ExecBindCon ¶
func (q *Query) ExecBindCon(sqlTemplate string, c dcon.ContainerReader, values map[string]dcon.PropertyID, key string) error
ExecBindCon - execution of the insert, update, delete command with the substitution of values in the template. For dcon.StrictContainer
func (*Query) FieldTypeIndex ¶
FieldTypeIndex - field type by index. Result: pgtype.BoolOID, ... etc
func (*Query) FieldTypeName ¶
FieldType - field type by name. Result: type name
func (*Query) FieldTypeNameIndex ¶
FieldTypeIndex - field type by index. Result: type name
func (*Query) Fields ¶
func (q *Query) Fields() []pgproto3.FieldDescription
Fields - list of fields (Select only)
func (*Query) Float32 ¶
Float32 - field value by name, converted to float32 (only for Select and after a successful Next call)
func (*Query) Float64 ¶
Float64 - field value by name, converted to float64 (only for Select and after a successful Next call)
func (*Query) Int ¶
Int - field value by name, converted to int64 (only for Select and after a successful Next call)
func (*Query) Int64 ¶
Int64 - field value by name, converted to int64 (only for Select and after a successful Next call)
func (*Query) LoadLargeObject ¶
LoadLargeObject - read Large Object from the database. If transaction == nil, then creates and closes the transaction automatically
func (*Query) RemoveLargeObject ¶
RemoveLargeObject - remove Large Object from the database. If transaction == nil, then creates and closes the transaction automatically
func (*Query) RowsAffected ¶
RowsAffected - the number of processed rows, for Select closes the query (Next will not work)
func (*Query) SaveLargeObject ¶
SaveLargeObject - write Large Object to the database. If oid == 0 then creates a new object. If transaction == nil, then creates and closes the transaction automatically Returns the id of the created or updated object
func (*Query) SelectBind ¶
SelectBind - executing the select command with the substitution of values in the template
func (*Query) SelectBindCon ¶
func (q *Query) SelectBindCon(sqlTemplate string, c dcon.ContainerReader, values map[string]dcon.PropertyID, key string) error
SelectBindCon - executing the select command with the substitution of values in the template. For dcon.StrictContainer
func (*Query) String ¶
String - field value by name, converted to string (only for Select and after a successful Next call)
func (*Query) Time ¶
Time - field value by name, converted to time.Time (only for Select and after a successful Next call)
func (*Query) Value ¶
Value - field value by name (only for Select and after a successful Next call)
func (*Query) ValueIndex ¶
ValueIndex - field value by index (only for Select and after a successful Next call)
type SqlBinder ¶
type SqlBinder struct {
// contains filtered or unexported fields
}
SqlBinder - substitution of values in the Sql query template
func NewSqlBinder ¶
NewSqlBinder - create SqlBinder key is used to exclude repeated parsing of identical queries. The result of parsing is saved
func (*SqlBinder) Bind ¶
Bind - replace the format bind in the Sql string :bind to the value of the value variable
func (*SqlBinder) BindValues ¶
Bind - replace the format bind in the Sql string :bind to the value of the value variable
func (*SqlBinder) IsVariableParsed ¶
IsVariableParsed - checks whether there is such a variable in the list of parsed
func (*SqlBinder) ParcedVariables ¶
ParcedVariables - list of variables in an SQL expression
type SqlBinderParser ¶
type SqlBinderParser struct {
// contains filtered or unexported fields
}
SqlBinderParser - parser for identifying variables of the form :var in an sql query
func NewSqlBinderParser ¶
func NewSqlBinderParser(sqlTemplate string) *SqlBinderParser
NewSqlBinderParser - create SqlBinderParser
func (*SqlBinderParser) Calculate ¶
func (p *SqlBinderParser) Calculate(values map[string]string) (string, error)
Calculate - substitute values into variables and get the result
func (*SqlBinderParser) IsVariableParsed ¶
func (p *SqlBinderParser) IsVariableParsed(v string) bool
IsVariableParsed - is the variable parsed
func (*SqlBinderParser) ParcedVariables ¶
func (p *SqlBinderParser) ParcedVariables() []string
ParcedVariables - list of variables in an SQL expression
func (*SqlBinderParser) Parse ¶
func (p *SqlBinderParser) Parse() error
func (*SqlBinderParser) SqlTemplate ¶
func (p *SqlBinderParser) SqlTemplate() string
SqlTemplate - SQL template
type TxNested ¶
type TxNested struct {
// contains filtered or unexported fields
}
TxNested - working with nested transactions
func NewTxNested ¶
NewTxNested - create a nested transaction management object based on pgx.Conn
func NewTxNestedPool ¶
NewTxNestedPool - create a nested transaction management object based on pgxpool.Conn
func (*TxNested) Begin ¶
Begin - start a transaction. If the transaction has already started, it is returned
func (*TxNested) Commit ¶
Commit - complete the transaction. If there are nested transactions, the operation is ignored
func (*TxNested) Connection ¶
func (t *TxNested) Connection() *pgx.Conn
Connection - active connection