getql

package module
v0.0.0-...-30237f2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

README

FYI, good luck reading and understanding ;P. God bless!

Documentation

Index

Constants

View Source
const (
	Sel = "SEL" // SELECT
	Frm = "FRM" // FROM

	Lim = "LIM" // LIMIT
	Off = "OFF" // OFFSET

	Page   = "PAGE"
	Filter = "FILTER"
)

Suffixes

View Source
const (
	Count = "COUNT(*)"
	Asc   = "ASC"
	Desc  = "DESC"
	And   = "AND"
	Or    = "OR"
)

SQL Keywords

View Source
const (
	Eq      = "EQ"
	Ne      = "NE"
	In      = "IN"
	Gt      = "GT"
	Ge      = "GE"
	Lt      = "LT"
	Le      = "LE"
	Null    = "NULL"
	NotNull = "NOTNULL"
	Like    = "LIKE"
	ILike   = "ILIKE"
	Between = "BETWEEN"
	Ignore  = "IGNORE"
)

Operators

View Source
const Sep = "."

The separator between the prefixes and suffix

Variables

This section is empty.

Functions

func AddKeywords

func AddKeywords(funcs map[string]interface{}) map[string]interface{}

func AddOperatorKV

func AddOperatorKV(funcs map[string]interface{}) map[string]interface{}

func Aor

func Aor(strs ...string) string

func Col

func Col(strs ...string) string

func Date

func Date(params map[string][]string) func(string, string, string) template.HTML

func DateNode

func DateNode(name, value, class string) (node *html.Node)

func FilterCheckbox

func FilterCheckbox(params map[string][]string) func() template.HTML

func Funcs

func Funcs(funcs map[string]interface{}, params map[string][]string) map[string]interface{}

func IsValidSuffix

func IsValidSuffix(suffix string) bool

func Join

func Join(items ...interface{}) string

func Multinumber

func Multinumber(params map[string][]string) func(string, string, string) template.HTML

func Multiselect

func Multiselect(params map[string][]string) func(string, []KV, string, string) template.HTML

func MultiselectOptional

func MultiselectOptional(params map[string][]string) func(string, []KV, string, string) template.HTML

func Multitext

func Multitext(params map[string][]string) func(string, string, string) template.HTML

func Number

func Number(params map[string][]string) func(string, string, string) template.HTML

func NumberNode

func NumberNode(name, value, class string) (node *html.Node)

func Opr

func Opr(strs ...string) string

func Ord

func Ord(strs ...string) string

func PaginateHandlerFunc

func PaginateHandlerFunc(url string, delta int, errorHandler func(http.ResponseWriter, *http.Request, error)) http.HandlerFunc

func ReplacePlaceholders

func ReplacePlaceholders(query string) string

Replace all ? with postgres placeholders $<number>

func ResolvePage

func ResolvePage(params map[string][]string) map[string][]string

func ScrubForm

func ScrubForm(form url.Values) url.Values

func ScrubRequest

func ScrubRequest(r *http.Request) *http.Request

func ScrubUrl

func ScrubUrl(url string, form url.Values) string

func Select

func Select(params map[string][]string) func(string, []KV, string, string) template.HTML

func SelectNode

func SelectNode(name string, values []KV, selected, class string) (node *html.Node)

func SelectOptional

func SelectOptional(params map[string][]string) func(string, []KV, string, string) template.HTML

func Subst

func Subst(query string, args ...interface{}) string

func Text

func Text(params map[string][]string) func(string, string, string) template.HTML

func TextNode

func TextNode(name, value, class string) (node *html.Node)

func Val

func Val(strs ...string) string

Types

type KV

type KV struct {
	Key   string
	Value string
}

type OrderBy

type OrderBy struct {
	Column string
	Order  string // "ASC" or "DESC"
}

func (OrderBy) String

func (orderby OrderBy) String() string

type Pred

type Pred struct {
	Column   string
	Operator string
	Value    string
	Values   []string
	Nested   bool
	PredGrp  *PredGrp
}

Column Operator Value/Values name = 'bob' name IN ('bob', 'alice')

type PredGrp

type PredGrp struct {
	Or    bool
	Preds map[string]*Pred
}

type SelectOption

type SelectOption func(SelectQuery) SelectQuery
var SelectAll SelectOption = func(sq SelectQuery) SelectQuery {
	sq.Select = []string{"*"}
	return sq
}
var SelectCount SelectOption = func(sq SelectQuery) SelectQuery {
	sq.Select = []string{Count}
	sq.OrderBys = nil
	sq.Limit = 0
	sq.Offset = 0
	return sq
}
var WhereOnly SelectOption = func(sq SelectQuery) SelectQuery {
	sq.Select = nil
	sq.From = ""
	sq.OrderBys = nil
	sq.Limit = 0
	sq.Offset = 0
	return sq
}

type SelectQuery

type SelectQuery struct {
	Select   []string
	From     string
	Where    *PredGrp
	OrderBys []OrderBy
	Limit    int
	Offset   int
}

func ParseSelect

func ParseSelect(params map[string][]string) (query SelectQuery)

func (SelectQuery) Sql

func (sq SelectQuery) Sql(options ...SelectOption) (query string, args []interface{})

type SelectStats

type SelectStats struct {
	Query      string
	Total      int
	Limit      int
	Page       int
	TotalPages int
}

func DBSelectWithStats

func DBSelectWithStats(db *sqlx.DB, params map[string][]string, options ...SelectStatsOption) (rows *sqlx.Rows, stats SelectStats, err error)

type SelectStatsConfig

type SelectStatsConfig struct {
	MinimumLimit int
	QueryOptions []SelectOption
}

type SelectStatsOption

type SelectStatsOption func(SelectStatsConfig) SelectStatsConfig
var SelectStatsQueryAll SelectStatsOption = func(config SelectStatsConfig) SelectStatsConfig {
	config.QueryOptions = append(config.QueryOptions, SelectAll)
	return config
}

func SelectStatsMinimumLimit

func SelectStatsMinimumLimit(limit int) SelectStatsOption

Jump to

Keyboard shortcuts

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