urlvalues

package
v0.0.0-...-202847b Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: Apache-2.0, BSD-2-Clause Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	Deterministic bool // if true internal map gets printed in its order, otherwise flaky tests.
	Values        Values
	// contains filtered or unexported fields
}

URLFilter is used with Query.Apply to add WHERE clauses from the URL values:

  • ?foo=bar - Where(`"foo" = 'bar'`)
  • ?foo=hello&foo=world - Where(`"foo" IN ('hello','world')`)
  • ?foo__eq=bar - Where(`"foo" = 'bar'`)
  • ?foo__neq=bar - Where(`"foo" != 'bar'`)
  • ?foo__exclude=bar - Where(`"foo" != 'bar'`)
  • ?foo__gt=42 - Where(`"foo" > 42`)
  • ?foo__gte=42 - Where(`"foo" >= 42`)
  • ?foo__from=42&foo__to=100 - Where(`"foo" >= 42` AND `foo` <= 100)
  • ?foo__lt=42 - Where(`"foo" < 42`)
  • ?foo__lte=42 - Where(`"foo" <= 42`)
  • ?foo__null= - Where(`"foo" IS NULL`)
  • ?foo__notnull= - Where(`"foo" IS NOT NULL`)
  • ?foo__lte=42&foo__sort=desc - WHERE `foo` <= 42 ORDER BY `foo` DESC
  • ?foo__lte=42&foo__sort=asc - WHERE `foo` <= 42 ORDER BY `foo` ASC
  • ?foo__like=bar - Where(`"foo" LIKE 'bar'`)
  • ?foo__nlike=bar - Where(`"foo" NOT LIKE 'bar'`)
  • ?foo__match=bar - Where(`"foo" SIMILAR TO 'bar'`)
  • ?foo__ss=bar - Where(`"foo" <=> 'bar'`) // space ship operator

func NewFilter

func NewFilter(values Values) *Filter

func (*Filter) Allow

func (f *Filter) Allow(filters ...string)

Allow only columnName__operators are allowed

func (*Filter) Filters

func (f *Filter) Filters(tbl *ddl.Table, cond dml.Conditions) (_ dml.Conditions, sortOrder []string)

Filters builds the SQL conditions by appending to slice `cond` and returning it.

type Pager

type Pager struct {
	Limit  uint64
	Offset uint64

	// Default max limit is 1000.
	MaxLimit uint64
	// Default max offset is 1000000.
	MaxOffset uint64
	// contains filtered or unexported fields
}

func NewPager

func NewPager(values Values) *Pager

func (*Pager) FromValues

func (p *Pager) FromValues(values Values) error

func (*Pager) GetLimit

func (p *Pager) GetLimit() uint64

func (*Pager) GetOffset

func (p *Pager) GetOffset() uint64

func (*Pager) Pagination

func (p *Pager) Pagination(a *dml.DBR) (*dml.DBR, error)

type Values

type Values map[string][]string

Values same as net/url so use url.ParseQuery to get a parsed query string.

func (Values) Bool

func (v Values) Bool(name string) (bool, error)

func (Values) Duration

func (v Values) Duration(name string) (time.Duration, error)

func (Values) Float64

func (v Values) Float64(name string) (float64, error)

func (Values) Has

func (v Values) Has(name string) bool

func (Values) Int

func (v Values) Int(name string) (int, error)

func (Values) Int64

func (v Values) Int64(name string) (int64, error)

func (Values) MaybeBool

func (v Values) MaybeBool(name string) bool

func (Values) MaybeDuration

func (v Values) MaybeDuration(name string) time.Duration

func (Values) MaybeFloat64

func (v Values) MaybeFloat64(name string) float64

func (Values) MaybeInt

func (v Values) MaybeInt(name string) int

func (Values) MaybeInt64

func (v Values) MaybeInt64(name string) int64

func (Values) MaybeTime

func (v Values) MaybeTime(name string) time.Time

func (Values) Pager

func (v Values) Pager() *Pager

func (Values) SetDefault

func (v Values) SetDefault(name string, values ...string)

func (Values) String

func (v Values) String(name string) string

func (Values) Strings

func (v Values) Strings(name string) []string

func (Values) Time

func (v Values) Time(name string) (time.Time, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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