Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeComparisonScopeBuildFunc ¶
func MakeComparisonScopeBuildFunc(columns ...string) func(comparisons ...Comparison) func(values ...interface{}) func(*gorm.DB) *gorm.DB
MakeComparisonScopeBuildFunc 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
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) 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 Order ¶
type Order string
Order is an ORDER BY clause specified in SQL, and represents the sort order.
func ReverseOrders ¶
ReverseOrders returns a slice of Order converted from ASC to DESC, DESC to ASC.
Example ¶
fmt.Printf("%v\n", ReverseOrders([]Order{ASC, DESC, DESC})) fmt.Printf("%v\n", ReverseOrders([]Order{DESC, ASC, ASC}))
Output: [desc asc asc] [asc desc desc]