types

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagFilter = "filter"
)

Variables

This section is empty.

Functions

func BoolFiltering

func BoolFiltering(filterVal bool, filedNames ...string) func(*gorm.DB) *gorm.DB

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

func FixWhereClausesForStatementModifier(stmt *gorm.Statement)

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

func SkipBoolFilter(filedNames ...string) func(*gorm.DB) *gorm.DB

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 Audit

type Audit struct {
	CreatedAt time.Time `json:"createdAt,omitempty"`
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
	CreatedBy uuid.UUID `json:"createdBy,omitempty"`
	UpdatedBy uuid.UUID `json:"updatedBy,omitempty"`
}

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

func (FilterBool) Value

func (t FilterBool) Value() (driver.Value, error)

Value implements driver.Valuer

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 (NoopStatementModifier) MergeClause

func (sm NoopStatementModifier) MergeClause(*clause.Clause)

func (NoopStatementModifier) Name

func (sm NoopStatementModifier) Name() string

type SoftDelete

type SoftDelete struct {
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleteAt,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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