Documentation ¶
Index ¶
- Constants
- func IsFieldSet(f Fields, key string) bool
- func SetGlobalModelStore(m ModelStore)
- func Update(db DBHandlers, ctx logger.WithLogger, obj common.Object, fields Fields) error
- func UpdateAll(db DBHandlers, ctx logger.WithLogger, obj interface{}, fields Fields) error
- func UpdateMulti(db DBHandlers, ctx logger.WithLogger, obj interface{}, filter Fields, ...) error
- func UpdateWithFilter(db DBHandlers, ctx logger.WithLogger, obj interface{}, filter *Filter, ...) error
- type AllDatabases
- type BetweenFields
- type Cursor
- type DB
- type DBConfig
- type DBHandlers
- type Fields
- type Filter
- func (f *Filter) AddBetweenField(fromField string, toField string, value interface{})
- func (f *Filter) AddField(name string, value interface{})
- func (f *Filter) AddFieldIn(name string, values ...interface{})
- func (f *Filter) AddFieldNotIn(name string, values ...interface{})
- func (f *Filter) AddFields(fields Fields)
- func (f *Filter) AddInterval(name string, from interface{}, to interface{})
- func (f *Filter) AddOrFields(value interface{}, names ...string)
- func (f *Filter) PopPresetFields()
- func (f *Filter) PushPresetFields(fields Fields)
- func (f *Filter) SetSorting(field string, direction ...string)
- func (f *Filter) ToQuery() *Query
- func (f *Filter) ToQueryString() string
- type FilterConfig
- type FilterParser
- type FilterValidator
- type Interval
- type JoinBegin
- type JoinEnd
- type JoinPairBase
- type JoinPairData
- type JoinQueries
- type JoinQuery
- type JoinQueryBase
- type JoinQueryBuilder
- type JoinQueryConfig
- type JoinQueryData
- type JoinTableBase
- type JoinTableData
- type Joiner
- type ModelStore
- type MonthPartition
- type OrFields
- type Query
- type QueryBetweenFields
- type QueryInterval
- type QueryOrFields
- type Transaction
- type TransactionHandler
- type WithDB
- type WithDBBase
- type WithFilterParser
Constants ¶
View Source
const ( SORT_ASC string = "ASC" SORT_DESC string = "DESC" )
Variables ¶
This section is empty.
Functions ¶
func IsFieldSet ¶
func SetGlobalModelStore ¶
func SetGlobalModelStore(m ModelStore)
func Update ¶
func Update(db DBHandlers, ctx logger.WithLogger, obj common.Object, fields Fields) error
func UpdateAll ¶
func UpdateAll(db DBHandlers, ctx logger.WithLogger, obj interface{}, fields Fields) error
func UpdateMulti ¶
func UpdateMulti(db DBHandlers, ctx logger.WithLogger, obj interface{}, filter Fields, fields Fields) error
func UpdateWithFilter ¶
func UpdateWithFilter(db DBHandlers, ctx logger.WithLogger, obj interface{}, filter *Filter, fields Fields) error
Types ¶
type AllDatabases ¶
type AllDatabases struct {
// contains filtered or unexported fields
}
func Databases ¶
func Databases() *AllDatabases
func (*AllDatabases) CloseAll ¶
func (a *AllDatabases) CloseAll()
func (*AllDatabases) Register ¶
func (a *AllDatabases) Register(db DB)
func (*AllDatabases) Unregister ¶
func (a *AllDatabases) Unregister(db DB)
type BetweenFields ¶
type Cursor ¶
type Cursor interface { Next(ctx logger.WithLogger) (bool, error) Close(ctx logger.WithLogger) error Scan(ctx logger.WithLogger, obj interface{}) error }
type DB ¶
type DB interface { WithFilterParser ID() string Clone() DB InitWithConfig(ctx logger.WithLogger, vld validator.Validator, cfg *DBConfig) error DBHandlers EnableVerboseErrors(bool) AutoMigrate(ctx logger.WithLogger, models []interface{}) error MigrateDropIndex(ctx logger.WithLogger, model interface{}, indexName string) error PartitionedMonthAutoMigrate(ctx logger.WithLogger, models []interface{}) error PartitionedMonthsDetach(ctx logger.WithLogger, table string, months []utils.Month) error PartitionedMonthsDelete(ctx logger.WithLogger, table string, months []utils.Month) error NativeHandler() interface{} Close() }
type DBHandlers ¶
type DBHandlers interface { FindByField(ctx logger.WithLogger, field string, value interface{}, obj interface{}, dest ...interface{}) (found bool, err error) FindByFields(ctx logger.WithLogger, fields Fields, obj interface{}, dest ...interface{}) (found bool, err error) FindWithFilter(ctx logger.WithLogger, filter *Filter, docs interface{}, dest ...interface{}) (int64, error) FindForUpdate(ctx logger.WithLogger, fields Fields, obj interface{}) (bool, error) Exists(ctx logger.WithLogger, filter *Filter, doc interface{}) (bool, error) Create(ctx logger.WithLogger, obj interface{}) error CreateDup(ctx logger.WithLogger, obj interface{}, ignoreConflict ...bool) (bool, error) Delete(ctx logger.WithLogger, obj common.Object) error DeleteByField(ctx logger.WithLogger, field string, value interface{}, model interface{}) error DeleteByFields(ctx logger.WithLogger, fields Fields, obj interface{}) error RowsWithFilter(ctx logger.WithLogger, filter *Filter, obj interface{}) (Cursor, error) AllRows(ctx logger.WithLogger, obj interface{}) (Cursor, error) Update(ctx logger.WithLogger, obj interface{}, filter Fields, fields Fields) error UpdateAll(ctx logger.WithLogger, obj interface{}, newFields Fields) error UpdateWithFilter(ctx logger.WithLogger, obj interface{}, filter *Filter, newFields Fields) error Join(ctx logger.WithLogger, joinConfig *JoinQueryConfig, filter *Filter, dest interface{}) (int64, error) Joiner() Joiner CreateDatabase(ctx logger.WithLogger, dbName string) error MakeExpression(expr string, args ...interface{}) interface{} Sum(ctx logger.WithLogger, groupFields []string, sumFields []string, filter *Filter, model interface{}, dest ...interface{}) (int64, error) Transaction(handler TransactionHandler) error EnableDebug(bool) }
type Filter ¶
type Filter struct { FilterConfig Fields Fields FieldsIn map[string][]interface{} FieldsNotIn map[string][]interface{} Intervals map[string]*Interval BetweenFields []*BetweenFields OrFields []*OrFields PresetFields []Fields NoLimit bool }
func ParseQuery ¶
func (*Filter) AddBetweenField ¶
func (*Filter) AddFieldIn ¶
func (*Filter) AddFieldNotIn ¶
func (*Filter) AddInterval ¶
func (*Filter) AddOrFields ¶
func (*Filter) PopPresetFields ¶
func (f *Filter) PopPresetFields()
func (*Filter) PushPresetFields ¶
func (*Filter) SetSorting ¶
func (*Filter) ToQueryString ¶
type FilterConfig ¶
type FilterConfig struct { SortField string `json:"sort_field,omitempty"` SortDirection string `json:"sort_direction,omitempty" validate:"omitempty,oneof=ASC DESC" vmessage:"Sort direction can be either ASC or DESC"` Offset int `json:"offset,omitempty" validate:"gte=0" vmessage:"Offset can not be negative"` Limit int `json:"limit,omitempty" validate:"gte=0" vmessage:"Limit can not be negative"` Count bool `json:"count,omitempty"` }
type FilterParser ¶
type FilterValidator ¶
type FilterValidator struct { Validator validator.Validator Rules map[string]string PlainFieldNames bool }
func EmptyFilterValidator ¶
func EmptyFilterValidator(vld validator.Validator) *FilterValidator
type JoinPairBase ¶
type JoinPairBase struct {
JoinPairData
}
func (*JoinPairBase) LeftField ¶
func (j *JoinPairBase) LeftField() string
func (*JoinPairBase) RightField ¶
func (j *JoinPairBase) RightField() string
type JoinPairData ¶
type JoinQueries ¶
type JoinQueries struct {
// contains filtered or unexported fields
}
func NewJoinQueries ¶
func NewJoinQueries() *JoinQueries
func (*JoinQueries) FindOrCreate ¶
func (j *JoinQueries) FindOrCreate(config *JoinQueryConfig) (JoinQuery, error)
type JoinQuery ¶
type JoinQuery interface {
Join(ctx logger.WithLogger, filter *Filter, dest interface{}) (int64, error)
}
type JoinQueryBase ¶
type JoinQueryBase struct {
JoinQueryData
}
func (*JoinQueryBase) Destination ¶
func (j *JoinQueryBase) Destination() interface{}
func (*JoinQueryBase) SetDestination ¶
func (j *JoinQueryBase) SetDestination(destination interface{})
type JoinQueryBuilder ¶
type JoinQueryConfig ¶
type JoinQueryConfig struct { Builder JoinQueryBuilder Name string Nocache bool }
func NewJoin ¶
func NewJoin(builder JoinQueryBuilder, name string, nocache ...bool) *JoinQueryConfig
type JoinQueryData ¶
type JoinQueryData struct {
// contains filtered or unexported fields
}
type JoinTableBase ¶
type JoinTableBase struct {
JoinTableData
}
func (*JoinTableBase) Model ¶
func (j *JoinTableBase) Model() interface{}
type JoinTableData ¶
type JoinTableData struct {
Model interface{}
}
type ModelStore ¶
type ModelStore interface { RegisterModel(model interface{}) FindModel(name string) interface{} AllModels() []interface{} }
func GlobalModelStore ¶
func GlobalModelStore() ModelStore
type MonthPartition ¶
type MonthPartition struct { common.ObjectBase Table string `gorm:"index;uniqueIndex:u_month_partition"` Month utils.Month `gorm:"index;uniqueIndex:u_month_partition"` }
type Query ¶
type Query struct { FilterConfig Fields map[string]string `json:"fields,omitempty"` FieldsIn map[string][]string `json:"fields_in,omitempty"` FieldsNotIn map[string][]string `json:"fields_not_in,omitempty"` Intervals map[string]QueryInterval `json:"intervals,omitempty"` BetweenFields []QueryBetweenFields `json:"betwees_fields,omitempty"` OrFields []QueryOrFields `json:"or_fields,omitempty"` }
type QueryBetweenFields ¶
type QueryInterval ¶
type QueryOrFields ¶
type Transaction ¶
type Transaction interface { DBHandlers }
type TransactionHandler ¶
type TransactionHandler = func(tx Transaction) error
type WithDBBase ¶
type WithDBBase struct {
// contains filtered or unexported fields
}
func (*WithDBBase) Db ¶
func (w *WithDBBase) Db() DB
func (*WithDBBase) Init ¶
func (w *WithDBBase) Init(db DB)
type WithFilterParser ¶
type WithFilterParser interface { PrepareFilterParser(model interface{}, name string, validator ...*FilterValidator) (FilterParser, error) ParseFilter(query *Query, parserName string) (*Filter, error) ParseFilterDirect(query *Query, model interface{}, name string, validator ...*FilterValidator) (*Filter, error) }
Click to show internal directories.
Click to hide internal directories.