Documentation ¶
Index ¶
- func MakeComparisonScope(columns []string, comparisons []Comparison, nullsOrders []NullsOrder, ...) func(*gorm.DB) *gorm.DB
- func OrderClauseBuilder(columns ...string) func(orders ...string) string
- func ReverseOrders(orders []string) []string
- type Comparison
- type CursorSegment
- func (seg CursorSegment) Bool() bool
- func (seg CursorSegment) BoolPtr() *bool
- func (seg CursorSegment) Int64() int64
- func (seg CursorSegment) Int64Ptr() *int64
- func (seg CursorSegment) Interface(ty reflect.Type, column string) interface{}
- func (seg CursorSegment) IsNil() bool
- func (seg CursorSegment) Time() *time.Time
- type CursorSegments
- type CursorString
- type NullsOrder
- type Order
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeComparisonScope ¶
func MakeComparisonScope(columns []string, comparisons []Comparison, nullsOrders []NullsOrder, values []interface{}) func(*gorm.DB) *gorm.DB
MakeComparisonScope returns a GORM scope builder. This scope add a where clauses filtered by comparisons ranges.
func OrderClauseBuilder ¶
OrderClauseBuilder returns a function that create ORDER BY clause to specifies the order of DB records.
Example ¶
fmt.Printf("%s\n", OrderClauseBuilder("ID", "CreatedAt")("asc", "ASC")) fmt.Printf("%s\n", OrderClauseBuilder("ID", "CreatedAt")("desc", "DESC")) fmt.Printf("%s\n", OrderClauseBuilder("ID", "CreatedAt")("ASC", "desc"))
Output: id ASC, created_at ASC id DESC, created_at DESC id ASC, created_at DESC
func ReverseOrders ¶
ReverseOrders returns a slice of Order converted from ASC to DESC, DESC to ASC, FIRST to LAST, LAST to FIRST.
Example ¶
fmt.Printf("%#v\n", ReverseOrders([]string{"asc", "DESC", "desc nulls first"})) fmt.Printf("%#v\n", ReverseOrders([]string{"DESC", "asc", "ASC NULLS LAST"}))
Output: []string{"DESC", "ASC", "ASC NULLS LAST"} []string{"ASC", "DESC", "DESC NULLS FIRST"}
Types ¶
type Comparison ¶
type Comparison string
Comparison is a comparison operator used by where clause in SQL.
const ( // GreaterThan means that the column value in DB record is greater than the specified value. GreaterThan Comparison = ">" // LessThan means that the column value in DB record is less than the specified value. LessThan Comparison = "<" )
type CursorSegment ¶
type CursorSegment struct {
// contains filtered or unexported fields
}
CursorSegment is a result of parsing each element of cursor.
func (CursorSegment) Bool ¶ added in v2.2.2
func (seg CursorSegment) Bool() bool
Bool returns converted to bool.
func (CursorSegment) BoolPtr ¶ added in v2.2.2
func (seg CursorSegment) BoolPtr() *bool
BoolPtr returns converted to pointer of bool.
func (CursorSegment) Int64 ¶
func (seg CursorSegment) Int64() int64
Int64 returns converted to integer.
func (CursorSegment) Int64Ptr ¶
func (seg CursorSegment) Int64Ptr() *int64
Int64Ptr returns converted to pointer of integer.
func (CursorSegment) Interface ¶
func (seg CursorSegment) Interface(ty reflect.Type, column string) interface{}
Interface returns converted to the type of the specified column.
func (CursorSegment) IsNil ¶
func (seg CursorSegment) IsNil() bool
IsNil returns true if it have nil value. Otherwise, it returns false.
func (CursorSegment) Time ¶
func (seg CursorSegment) Time() *time.Time
Time returns converted to time.
type CursorSegments ¶
type CursorSegments []CursorSegment
CursorSegments is slice of CursorSegment.
func NewCursorSegments ¶
func NewCursorSegments(str CursorString) CursorSegments
NewCursorSegments create a CursorSegments from CursorString,
Example ¶
segments := NewCursorSegments("1585706584.025_20") fmt.Println(segments[0].Time().UTC().String()) fmt.Println(segments[1].Int64())
Output: 2020-04-01 02:03:04.025 +0000 UTC 20
type CursorString ¶
type CursorString string
CursorString is a string indicating the Cursor.
func FormatCursorString ¶
func FormatCursorString(args ...interface{}) CursorString
FormatCursorString returns a CursorString.
Example ¶
format := "2006-01-02T15:04:05.9999" ti, _ := time.Parse(format, "2020-04-01T02:03:04") fmt.Println(FormatCursorString(ti, 1, 3.5))
Output: 1585706584_1_3
func (CursorString) Validate ¶
func (cs CursorString) Validate() bool
Validate returns true, if it is valid. Otherwise, it returns false.
type NullsOrder ¶
type NullsOrder int
NullsOrder is how to handle null values when sorting.
const ( // TreatsAsEngineDefault is the default behavior of the engine. TreatsAsEngineDefault NullsOrder = iota // TreatsAsLowest is that Null values are treated as the lowest. TreatsAsLowest // TreatsAsHighest is that Null values are treated as the highest. TreatsAsHighest )