rsql

package module
v0.0.0-...-f9fceb7 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2021 License: MIT Imports: 12 Imported by: 0

README ¶

Go RSQL

🔨 Installation

go get github.com/si3nloong/go-rsql

type QueryParams struct {
    Name   string  `rsql:"n,filter,sort,allow=eq|gt|gte"`
    Status string  `rsql:"status,filter"`
    PtrStr *string `rsql:"text,filter"`
    No     int     `rsql:"no,column=No2,filter"`
}

func main() {
    p := MustNew(i)

    params, err := p.ParseQuery(`filter=status=eq="111";no=gt=1991;text==null&sort=status,-no`)
    if err != nil {
        panic(err)
    }

    log.Println(params.Filters)
    log.Println(params.Sorts)
}

📄 License

MIT

Copyright (c) 2020-present, SianLoong Lee

Documentation ¶

Index ¶

Constants ¶

View Source
const (
	Expression = iota
	String
	Or
	And
	Numeric
	Text
	Group
	Whitespace
)

types :

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type Direction ¶

type Direction int
const (
	Asc Direction = iota
	Desc
)

type Expr ¶

type Expr int

Expr :

const (
	Equal Expr = iota
	NotEqual
	LesserThan
	LesserOrEqual
	GreaterThan
	GreaterOrEqual
	In
	NotIn
	Like
	NotLike
)

types :

func (Expr) String ¶

func (e Expr) String() string

type Filter ¶

type Filter struct {
	Name     string
	Operator Expr
	Value    interface{}
}

Filter :

type Filters ¶

type Filters []Filter

func (Filters) Lookup ¶

func (fs Filters) Lookup(key string) (val interface{}, ok bool)

type FormatFunc ¶

type FormatFunc func(string) string

FormatFunc :

type Params ¶

type Params struct {
	Selects []string
	Filters Filters
	Sorts   []Sort
	Limit   uint
	Offset  uint
	Cursor  string
}

Params :

type RSQL ¶

type RSQL struct {
	SelectTag string
	FilterTag string
	SortTag   string
	LimitTag  string
	PageTag   string

	FormatColumn FormatFunc
	DefaultLimit uint
	MaxLimit     uint
	// contains filtered or unexported fields
}

RSQL :

func MustNew ¶

func MustNew(src interface{}) *RSQL

MustNew :

func New ¶

func New(src interface{}) (*RSQL, error)

New :

func (*RSQL) ParseQuery ¶

func (p *RSQL) ParseQuery(query string) (*Params, error)

ParseQuery :

func (*RSQL) ParseQueryBytes ¶

func (p *RSQL) ParseQueryBytes(query []byte) (*Params, error)

ParseQueryBytes :

type Sort ¶

type Sort struct {
	Field     string
	Direction Direction
}

Sort :

type Strings ¶

type Strings []string

Strings :

func (Strings) IndexOf ¶

func (slice Strings) IndexOf(search string) (idx int)

IndexOf :

type Struct ¶

type Struct struct {
	Fields []*StructField
	Names  map[string]*StructField
}

Struct :

type StructField ¶

type StructField struct {
	Name string
	Tag  *StructTag
	Type reflect.Type
}

StructField :

type StructTag ¶

type StructTag struct {
	// contains filtered or unexported fields
}

StructTag :

func NewTag ¶

func NewTag(name string, tag reflect.StructTag) *StructTag

NewTag :

func (StructTag) Lookup ¶

func (t StructTag) Lookup(key string) (value string, ok bool)

type Token ¶

type Token struct {
	Type        int
	Value       string
	Lexeme      []byte
	TC          int
	StartLine   int
	StartColumn int
	EndLine     int
	EndColumn   int
}

Jump to

Keyboard shortcuts

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