postgres

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout           = 50 * time.Millisecond
	DefaultConnectionTimeout = 250 * time.Millisecond
	DefaultRedialInterval    = 100 * time.Millisecond
	DefaultPingInterval      = 1 * time.Second
	DefaultPoolSize          = 5
)

Константы определяющие дефолтное поведение конектора к postgres-у

View Source
const MaxLimit uint16 = 10000

Variables

View Source
var (
	ErrConnection = fmt.Errorf("error dial to box")
)

Functions

func GenerateSelectAll

func GenerateSelectAll(tableName string, fieldNames []string) (string, error)

func QuoteIdentifier

func QuoteIdentifier(s string) string

Types

type BYTEA

type BYTEA []byte

type BaseField

type BaseField struct {
	activerecord.BaseField
	UpdateOps []Operation
}

type Condition

type Condition struct {
	Field  string
	Values []any
}

ToDo добавить поддержку разных условий. Больше меньше, не равно и т.д.

func (Condition) GetValues

func (c Condition) GetValues() [][]any

type Connection

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

func GetConnection

func GetConnection(ctx context.Context, postgresOpts *ConnectionOptions) (*Connection, error)

func (*Connection) Call

func (c *Connection) Call(ctx context.Context, sql string, args []any) (pgx.Rows, error)

func (*Connection) Close

func (c *Connection) Close()

func (*Connection) Done

func (c *Connection) Done() <-chan struct{}

func (*Connection) Info

func (c *Connection) Info() string

func (*Connection) InstanceMode

func (c *Connection) InstanceMode() any

type ConnectionOption

type ConnectionOption interface {
	// contains filtered or unexported methods
}

ConnectionOption - интерфейс которому должны соответствовать опции передаваемые в конструктор

func WithCredentials

func WithCredentials(username, password string) ConnectionOption

WithCredentials - если используется авторизация на уровне СУБД

func WithDatabase

func WithDatabase(dbName string) ConnectionOption

WithDatabase - имя базы данных

func WithPoolSize

func WithPoolSize(size int32) ConnectionOption

WithPoolSize - опция для изменения размера пулла подключений

func WithTimeout

func WithTimeout(connection time.Duration) ConnectionOption

WithTimeout - опция для изменений таймаутов

type ConnectionOptions

type ConnectionOptions struct {
	activerecord.BaseConnectionOptions
	// contains filtered or unexported fields
}

ConnectionOptions - опции используемые для подключения

func NewConnectionOptions

func NewConnectionOptions(server string, port uint16, mode activerecord.ServerModeType, opts ...ConnectionOption) (*ConnectionOptions, error)

NewConnectionOptions - создание структуры с опциями и дефолтными значениями. Для модификации значений по умолчанию, надо передавать опции в конструктор

type CursorPosition

type CursorPosition struct {
	Values []any
	Order  Order
}

type DefaultKeyword

type DefaultKeyword bool
const DefaultValueDB DefaultKeyword = true

type Index

type Index struct {
	Fields       OrderedFields
	Unique       bool
	Condition    []Condition
	DefaultLimit uint16
}

func (Index) CursorConditions

func (i Index) CursorConditions(c CursorPosition, paramsOffset int) (string, []any)

func (Index) MultiField

func (i Index) MultiField() bool

func (Index) OrderConditions

func (i Index) OrderConditions() string

func (Index) ValidateCursor

func (i Index) ValidateCursor(c CursorPosition) error

type OnConflictAction

type OnConflictAction uint8
const (
	Replace OnConflictAction = iota
	IgnoreDuplicate
	NoDuplicateAction
)

ToDo merge with octopus InsertModeInserOrReplace, e.t.c.

type Operation

type Operation struct {
	Field string
	Op    activerecord.OpCode
	Value any
}

type Order

type Order uint8
const (
	ASC Order = iota
	DESC
)

type OrderField

type OrderField struct {
	Field string
	Order Order
}

func (OrderField) String

func (of OrderField) String() string

type OrderedFields

type OrderedFields []OrderField

func (OrderedFields) GetFieldNames

func (ofs OrderedFields) GetFieldNames() []string

type Query

type Query struct {
	QueryString     string
	ConditionExists bool // Признак того, что уже есть условие в запросе
	Params          []any
}

func GenerateDelete

func GenerateDelete(tableName string, primaryKey Index, keys [][]any) (*Query, error)

func GenerateInsert

func GenerateInsert(tableName string, pk Index, fieldNames []string, values [][]any, returning []string, conflictAction OnConflictAction) (*Query, error)

func GenerateSelect

func GenerateSelect(tableName string, fieldNames []string, index Index, keys [][]any, offset, limit uint32, cursor CursorPosition) (*Query, error)

func GenerateUpdate

func GenerateUpdate(tableName string, primaryIndex Index, updates []UpdateParams) (*Query, error)

func NewDeleteQuery

func NewDeleteQuery(tableName string, pk Index) *Query

func NewInsertQuery

func NewInsertQuery(tableName string, fieldNames []string) *Query

func NewSelectQuery

func NewSelectQuery(tableName string, fieldNames []string, i Index) *Query

func NewUpdateQuery

func NewUpdateQuery(tableName string) *Query

func (*Query) AddLimitOffset

func (q *Query) AddLimitOffset(limit, offset uint32)

func (*Query) AddNoConflictDoNothing

func (q *Query) AddNoConflictDoNothing(fieldNames []string)

func (*Query) AddNoConflictDoUpdate

func (q *Query) AddNoConflictDoUpdate(tableName string, pk Index, fieldNames []string)

func (*Query) AddParams

func (q *Query) AddParams(key ...any) int

func (*Query) AddQuery

func (q *Query) AddQuery(cond string)

func (*Query) AddReturning

func (q *Query) AddReturning(fieldNames []string)

func (*Query) AddSetStatement

func (q *Query) AddSetStatement(field string, key any)

func (*Query) AddWhereBlock

func (q *Query) AddWhereBlock(cond ...string)

func (*Query) AddWhereCondition

func (q *Query) AddWhereCondition(cond string, key []any)

func (*Query) AddWhereQuery

func (q *Query) AddWhereQuery(cond string)

func (*Query) ConditionFields

func (q *Query) ConditionFields(fields []string)

func (*Query) GenerateWhereKeys

func (q *Query) GenerateWhereKeys(multiField bool, keys [][]any)

type QueryBuilderState

type QueryBuilderState uint8
const (
	QueryBuilderStateWhere QueryBuilderState = iota
	QueryBuilderStateOrderBy
	QueryBuilderStateLimit
	QueryBuilderStateOffset
)

type UpdateParams

type UpdateParams struct {
	PK  []any
	Ops []Operation
}

Jump to

Keyboard shortcuts

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