Documentation
¶
Index ¶
Constants ¶
const (
TagFilter = "filter"
)
Variables ¶
This section is empty.
Functions ¶
func BoolFiltering ¶
BoolFiltering is a gorm scope that change default/tag behavior of FilterBool field filtering with given field names e.g. db.WithContext(ctx).Scopes(BoolFiltering(false, "FieldName1", "FieldName2")).Find(...)
would filter out any model with "FieldName1" or "FieldName2" equals to "false"
To override all FilterBool filtering, provide no params or "*" e.g. db.WithContext(ctx).Scopes(BoolFiltering()).Find(...)
Note using this scope without context would panic
func FixWhereClausesForStatementModifier ¶
FixWhereClausesForStatementModifier applies special fix for db.Model(&model{}).Where(&model{f1:v1}).Or(&model{f2:v2})... Ref: https://github.com/go-gorm/gorm/issues/3627
https://github.com/go-gorm/gorm/commit/9b2181199d88ed6f74650d73fa9d20264dd134c0#diff-e3e9193af67f3a706b3fe042a9f121d3609721da110f6a585cdb1d1660fd5a3c
Important: utility function for go-lanai internal use
func SkipBoolFilter ¶
SkipBoolFilter is a gorm scope that can be used to skip filtering of FilterBool fields with given field names e.g. db.WithContext(ctx).Scopes(SkipBoolFilter("FieldName1", "FieldName2")).Find(...)
To disable all FilterBool filtering, provide no params or "*" e.g. db.WithContext(ctx).Scopes(SkipBoolFilter()).Find(...)
Note using this scope without context would panic
Types ¶
type FilterBool ¶
type FilterBool bool
FilterBool implements - schema.GormDataTypeInterface - schema.QueryClausesInterface this data type adds "WHERE" clause in SELECT statements for filtering out models based on this field's value
FilterBool by default filter out true values (WHERE filter_bool_col IS NOT TRUE AND ....). this behavior can be changed to using tag `filter:"<-|true|false>"`
- `filter:"-"`: disables the filtering at model declaration level. Can be enabled on per query basis using scopes or repo options (if applicable)
- `filter:"true"`: filter out "true" values, the default behavior Can be overridden on per query basis using scopes or repo options (if applicable)
- `filter:"false"`: filter out "false" values Can be overridden on per query basis using scopes or repo options (if applicable)
See SkipBoolFilter and BoolFiltering for filtering behaviour overriding
func (FilterBool) GormDataType ¶
func (t FilterBool) GormDataType() string
func (FilterBool) QueryClauses ¶
func (t FilterBool) QueryClauses(f *schema.Field) []clause.Interface
QueryClauses implements schema.QueryClausesInterface,
func (*FilterBool) Scan ¶
func (t *FilterBool) Scan(src interface{}) error
Scan implements sql.Scanner
type NoopStatementModifier ¶
type NoopStatementModifier struct{}
NoopStatementModifier used to be embedded of any StatementModifier implementation. This type implement dummy clause.Interface methods
func (NoopStatementModifier) Build ¶
func (sm NoopStatementModifier) Build(clause.Builder)
func (NoopStatementModifier) MergeClause ¶
func (sm NoopStatementModifier) MergeClause(*clause.Clause)
func (NoopStatementModifier) Name ¶
func (sm NoopStatementModifier) Name() string