postgres

package
v0.0.0-...-b8313d7 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 8 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 (
	Bool    activerecord.Format = "bool"    // BOOLEAN
	String  activerecord.Format = "string"  // CHARACTER(n) or CHAR(n) VARYING(n) VARCHAR(n) TEXT
	Int16   activerecord.Format = "int16"   // SMALLINT
	Int32   activerecord.Format = "int32"   // INTEGER
	Int64   activerecord.Format = "int64"   // BIGINT
	Float32 activerecord.Format = "float32" // real float8
	Float64 activerecord.Format = "float64" // float(n)

)

ToDo numeric or numeric(p,s) ToDo DATE TIME TIMESTAMP TIMESTAMPTZ INTERVAL

View Source
const (
	Backend activerecord.Backend = "postgres"
)
View Source
const MaxLimit uint16 = 10000

Variables

View Source
var DataFormat = []activerecord.Format{String}
View Source
var (
	ErrConnection = fmt.Errorf("error dial to box")
)
View Source
var NumericFormat = []activerecord.Format{Int16, Int32, Int64}

Functions

func GenerateSelectAll

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

func QuoteIdentifier

func QuoteIdentifier(s string) string

Types

type BaseField

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

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    []string
	DefaultLimit uint16
}

func (Index) ConditionFields

func (i Index) ConditionFields() string

func (Index) Conditions

func (i Index) Conditions() string

func (Index) CursorConditions

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

func (Index) GenerateWhereKeys

func (i Index) GenerateWhereKeys(q *Query, keys [][]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
	UpdateDuplicate
	NoDuplicateAction
)

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

type Ops

type Ops 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
	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)

type QueryBuilderState

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

type UpdateParams

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

Jump to

Keyboard shortcuts

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