Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateSelectAll(tableName string, fieldNames []string) (string, error)
- func QuoteIdentifier(s string) string
- type BaseField
- type Connection
- type ConnectionOption
- type ConnectionOptions
- type CursorPosition
- type DefaultKeyword
- type Index
- func (i Index) ConditionFields() string
- func (i Index) Conditions() string
- func (i Index) CursorConditions(c CursorPosition, paramsOffset int) (string, []any)
- func (i Index) GenerateWhereKeys(q *Query, keys [][]any)
- func (i Index) MultiField() bool
- func (i Index) OrderConditions() string
- func (i Index) ValidateCursor(c CursorPosition) error
- type OnConflictAction
- type Ops
- type Order
- type OrderField
- type OrderedFields
- type Query
- func GenerateDelete(tableName string, primaryKey Index, keys [][]any) (*Query, error)
- func GenerateInsert(tableName string, pk Index, fieldNames []string, values [][]any, ...) (*Query, error)
- func GenerateSelect(tableName string, fieldNames []string, index Index, keys [][]any, ...) (*Query, error)
- func GenerateUpdate(tableName string, primaryIndex Index, updates []UpdateParams) (*Query, error)
- func NewDeleteQuery(tableName string, pk Index) *Query
- func NewInsertQuery(tableName string, fieldNames []string) *Query
- func NewSelectQuery(tableName string, fieldNames []string, i Index) *Query
- func NewUpdateQuery(tableName string) *Query
- func (q *Query) AddLimitOffset(limit, offset uint32)
- func (q *Query) AddNoConflictDoNothing(fieldNames []string)
- func (q *Query) AddNoConflictDoUpdate(tableName string, pk Index, fieldNames []string)
- func (q *Query) AddParams(key ...any) int
- func (q *Query) AddQuery(cond string)
- func (q *Query) AddReturning(fieldNames []string)
- func (q *Query) AddSetStatement(field string, key any)
- func (q *Query) AddWhereBlock(cond ...string)
- func (q *Query) AddWhereCondition(cond string, key []any)
- type QueryBuilderState
- type UpdateParams
Constants ¶
const ( DefaultTimeout = 50 * time.Millisecond DefaultConnectionTimeout = 250 * time.Millisecond DefaultRedialInterval = 100 * time.Millisecond DefaultPingInterval = 1 * time.Second DefaultPoolSize = 5 )
Константы определяющие дефолтное поведение конектора к postgres-у
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
const (
Backend activerecord.Backend = "postgres"
)
const MaxLimit uint16 = 10000
Variables ¶
var AllFormat = append(append(append( NumericFormat, FloatFormat...), DataFormat...), Bool, )
var DataFormat = []activerecord.Format{String}
var (
ErrConnection = fmt.Errorf("error dial to box")
)
var FloatFormat = []activerecord.Format{Float32, Float64}
var NumericFormat = []activerecord.Format{Int16, Int32, Int64}
Functions ¶
func GenerateSelectAll ¶
func QuoteIdentifier ¶
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) 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 Index ¶
type Index struct { Fields OrderedFields Unique bool Condition []string DefaultLimit uint16 }
func (Index) ConditionFields ¶
func (Index) Conditions ¶
func (Index) CursorConditions ¶
func (i Index) CursorConditions(c CursorPosition, paramsOffset int) (string, []any)
func (Index) GenerateWhereKeys ¶
func (Index) MultiField ¶
func (Index) OrderConditions ¶
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 OrderField ¶
func (OrderField) String ¶
func (of OrderField) String() string
type OrderedFields ¶
type OrderedFields []OrderField
func (OrderedFields) GetFieldNames ¶
func (ofs OrderedFields) GetFieldNames() []string
type Query ¶
func GenerateDelete ¶
func GenerateInsert ¶
func GenerateSelect ¶
func GenerateUpdate ¶
func GenerateUpdate(tableName string, primaryIndex Index, updates []UpdateParams) (*Query, error)
func NewDeleteQuery ¶
func NewInsertQuery ¶
func NewUpdateQuery ¶
func (*Query) AddLimitOffset ¶
func (*Query) AddNoConflictDoNothing ¶
func (*Query) AddNoConflictDoUpdate ¶
func (*Query) AddReturning ¶
func (*Query) AddSetStatement ¶
func (*Query) AddWhereBlock ¶
func (*Query) AddWhereCondition ¶
type QueryBuilderState ¶
type QueryBuilderState uint8
const ( QueryBuilderStateWhere QueryBuilderState = iota QueryBuilderStateOrderBy QueryBuilderStateLimit QueryBuilderStateOffset )