Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Builder ¶
type Builder struct {
*Config
// contains filtered or unexported fields
}
Builder is a query builder. You should initialize it only once, and then use it in your http.Handler.
func MustNewBuilder ¶
MustNewBuilder creates a new builder and panic on failure
func NewBuilder ¶
NewBuilder initialize a Builder and parse the passing Model that will be used in the Parse calls.
type Config ¶
type Config struct {
// Model is an instance of the struct definition. the Builder will parse
// the url.Values according to this.
Model interface{}
// TagName is the name of the tag in the struct. defaults to "query".
TagName string
// Separator between field and command. defaults to "_".
Separator string
// IgnoreSort indicates if the builder should skip the sort process.
IgnoreSort bool
// SortParam is the name of the sort parameter.
// defaults to "sort"
SortParam string
// DefaultSort is the default sort string for the query builder.
// if the builder gets and empty sort parameter it'll add this default.
DefaultSort string
// LimitParam is the name of the limit parameter in the query string.
// defaults to "limit".
LimitParam string
// DefaultLimit is the default value for limit option. default to 25.
DefaultLimit int
// LimitMaxValue is the maximum value that accept valid parameter.
LimitMaxValue int
// OffsetParam is the name of the offset parameter in the query string.
// defaults to "offset"
OffsetParam string
// SearchOperator used to combine search condition together. defaults to "AND".
SearchOperator string
// ExplicitSelect - if true, the query will select the relevant specific columns.
// else will select '*'
ExplicitSelect bool
// OnlySelectNonDetailedFields - if true will select only the non 'detailed' fields
// true implies ExplicitSelect = true
OnlySelectNonDetailedFields bool
}
Config for the Builder constructor.
type DBQuery ¶
type DBQuery struct {
// the number of rows returned by the SELECT statement.
Limit int
// start querying from offset x. used for pagination.
Offset int
// used as a parameter for the gorm.Order method. example: "age desc, name"
Sort string
// CondExp and CondVal come together and used as a parameters for the gorm.Where
// method.
//
// examples:
// 1. Exp: "name = ?"
// Val: "a8m"
//
// 2. Exp: "id IN (?)"
// Val: []int{1,2,3}
//
// 3. Exp: "name = ? AND age >= ?"
// Val: "a8m", 22
CondExp string
CondVal []interface{}
// Select specify fields that you want to retrieve from database when querying.
// the default is to select all fields.
//
// Select: "DISTINCT id"
Select string
}
DBQuery are options for query a database
type ParseError ¶
type ParseError struct {
// contains filtered or unexported fields
}
ParseError is a typed error created dynamically based on the parsing failure.
type Searcher ¶
Searcher is the interface that wraps the Search method. Models that want to support search, need to implement this interface. if a "search" term is provided to the Parse method, the Builder will call the Search method with this value. the return value should be a search query for this term + its arguments. (we let gorm handle the escaping). If multiple search terms are provided, the Builder will use the SearchOperator to combine these search queries together.