Documentation ¶
Index ¶
Constants ¶
View Source
const ( DefaultTagName = "rql" DefaultFieldSep = "_" DefaultLimit = 25 DefaultMaxLimit = 100 )
View Source
const ( OffsetOp = "offset" LimitOp = "limit" SelectOp = "select" SortOp = "sort" )
Variables ¶
View Source
var ( ErrBlocValue = errors.New("bloc is a value") ErrBlocBracket = errors.New("bloc is a square bracket") ErrParenthesisMalformed = errors.New("parenthesis bloc is malformed") ErrUnregonizedBloc = errors.New("unrecognized bloc") ErrInvalidPlacementSqrBrBloc = errors.New("invalid formation of square brackets bloc") )
View Source
var (
ReservedRunes = []rune{' ', '&', '(', ')', ',', '=', '/', ';', '?', '|', '[', ']'}
)
Functions ¶
func Column ¶
Column is the default function that converts field name into a database column. It used to convert the struct fields into their database names. For example:
Username => username FullName => full_name HTTPCode => http_code
func IsValidField ¶ added in v0.1.3
Types ¶
type Config ¶
type Config struct { // TagName is an optional tag name for configuration. t defaults to "rql". TagName string // Model is the resource definition. The parser is configured based on its definition. // For example, given the following struct definition: // // type User struct { // Age int `rql:"filter,sort"` // Name string `rql:"filter"` // } // // In order to create a parser for the given resource, you will do it like so: // // var QueryParser = rql.NewParser(&rql.Config{ // Model: User{}, // }) // Model interface{} // FieldSep is the separator for nested fields in a struct. For example, given the following struct: // // type User struct { // Name string `rql:"filter"` // Address struct { // City string `rql:"filter"“ // } // } // // We assume the schema for this struct contains a column named "address_city". Therefore, the default // separator is underscore ("_"). But, you can change it to "." for convenience or readability reasons. // The parser will automatically convert it to underscore ("_"). If you want to control the name of // the column, use the "column" option in the struct definition. For example: // // type User struct { // Name string `rql:"filter,column=full_name"` // } // FieldSep string // ColumnFn is the function that translate the struct field string into a table column. // For example, given the following fields and their column names: // // FullName => "full_name" // HTTPPort => "http_port" // // It is preferred that you will follow the same convention that your ORM or other DB helper use. // For example, If you are using `gorm` you want to se this option like this: // // var QueryParser = rql.MustNewParser( // ColumnFn: gorm.ToDBName, // }) // ColumnFn func(string) string // Log the logging function used to log debug information in the initialization of the parser. // It defaults `to log.Printf`. Log func(string, ...interface{}) // DefaultLimit is the default value for the `Limit` field that returns when no limit supplied by the caller. // It defaults to 25. DefaultLimit int // LimitMaxValue is the upper boundary for the limit field. User will get an error if the given value is greater // than this value. It defaults to 100. LimitMaxValue int }
Config is the configuration for the parser.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func (*Parser) GetFieldValidationFunc ¶
func (p *Parser) GetFieldValidationFunc() ValidationFunc
type RqlRootNode ¶
type RqlRootNode struct { Node *RqlNode // contains filtered or unexported fields }
func (*RqlRootNode) Limit ¶
func (r *RqlRootNode) Limit() string
func (*RqlRootNode) Offset ¶
func (r *RqlRootNode) Offset() string
func (*RqlRootNode) Sort ¶
func (r *RqlRootNode) Sort() []Sort
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
func NewScanner ¶
func NewScanner() *Scanner
type Token ¶
type Token int
const ( // Special tokens Illegal Token = iota Eof // Literals Ident // fields, function names // Reserved characters Space // Ampersand // & OpeningParenthesis // ( ClosingParenthesis // ) Comma // , EqualSign // = Slash // / SemiColon // ; QuestionMark // ? AtSymbol // @ Pipe // | OpeningSquareBracket // [ ClosingSquareBracket // ] // Keywords And Or Equal Greater GreaterOrEqual Lower LowerOrEqual NotEqual )
type TokenBloc ¶
type TokenBloc []TokenString
type TokenString ¶
type TokenString struct {
// contains filtered or unexported fields
}
func NewTokenString ¶
func NewTokenString(t Token, s string) TokenString
type ValidationFunc ¶
Click to show internal directories.
Click to hide internal directories.