crud

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package crud implements nestjsx queries execution. See https://github.com/nestjsx/crud/wiki/Requests#description

Index

Constants

This section is empty.

Variables

View Source
var (
	Delim             = "||"
	DelimStr          = ","
	DefaultParamNames = &ParamNames{
		Fields:         []string{"fields", "select"},
		Search:         []string{"s"},
		Filter:         []string{"filter"},
		Or:             []string{"or"},
		Join:           []string{"join"},
		Sort:           []string{"sort"},
		Limit:          []string{"limit", "per_page"},
		Offset:         []string{"offset"},
		Page:           []string{"page"},
		Cache:          []string{"cache"},
		IncludeDeleted: []string{"include_deleted"},
	}
)
View Source
var ErrForbidden = &ErrResponse{
	HTTPStatusCode: http.StatusForbidden,
	StatusText:     "Forbidden.",
}
View Source
var ErrNotFound = &ErrResponse{
	HTTPStatusCode: http.StatusNotFound,
	StatusText:     "Resource not found.",
}
View Source
var ErrUnauthorized = &ErrResponse{
	HTTPStatusCode: http.StatusUnauthorized,
	StatusText:     "Unauthorized.",
}

Functions

func ErrBadRequest added in v1.0.9

func ErrBadRequest(err error) render.Renderer

func ErrForbiddenText added in v1.0.9

func ErrForbiddenText(txt string) render.Renderer

func ErrRender added in v1.0.9

func ErrRender(err error) render.Renderer

func ResponseList added in v1.0.9

func ResponseList[T pgparty.Storable, Q DatabaseListQuerier[T]](w http.ResponseWriter, r *http.Request, q Q)

Types

type Bool

type Bool bool

type BoolArray

type BoolArray []bool

type ComparisonOperator

type ComparisonOperator string
const (
	EQUALS              ComparisonOperator = "$eq"
	NOT_EQUALS          ComparisonOperator = "$ne"
	GREATER_THAN        ComparisonOperator = "$gt"
	LOWER_THAN          ComparisonOperator = "$lt"
	GREATER_THAN_EQUALS ComparisonOperator = "$gte"
	LOWER_THAN_EQUALS   ComparisonOperator = "$lte"
	STARTS              ComparisonOperator = "$starts"
	ENDS                ComparisonOperator = "$ends"
	CONTAINS            ComparisonOperator = "$cont"
	EXCLUDES            ComparisonOperator = "$excl"
	IN                  ComparisonOperator = "$in"
	NOT_IN              ComparisonOperator = "$notin"
	IS_NULL             ComparisonOperator = "$isnull"
	NOT_NULL            ComparisonOperator = "$notnull"
	BETWEEN             ComparisonOperator = "$between"
	EQUALS_LOW          ComparisonOperator = "$eqL"
	NOT_EQUALS_LOW      ComparisonOperator = "$neL"
	STARTS_LOW          ComparisonOperator = "$startsL"
	ENDS_LOW            ComparisonOperator = "$endsL"
	CONTAINS_LOW        ComparisonOperator = "$contL"
	EXCLUDES_LOW        ComparisonOperator = "$exclL"
	IN_LOW              ComparisonOperator = "$inL"
	NOT_IN_LOW          ComparisonOperator = "$notinL"
)

type CreateQueryParams

type CreateQueryParams struct {
	Fields         QueryFields
	Search         SCondition
	Filter         []QueryFilter
	Or             []QueryFilter
	Join           []QueryJoin
	Sort           []QuerySort
	Limit          *int
	Offset         *int
	Page           *int
	ResetCache     bool
	IncludeDeleted *int
}

type DatabaseListQuerier added in v1.0.9

type DatabaseListQuerier[T pgparty.Storable] interface {
	ResponseList() ([]pgparty.JsonViewer[T], error)
}

type ErrResponse added in v1.0.9

type ErrResponse struct {
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code

	StatusText string `json:"status"`          // user-level status message
	AppCode    int64  `json:"code,omitempty"`  // application-specific error code
	ErrorText  string `json:"error,omitempty"` // application-level error message, for debugging
}

ErrResponse renderer type for handling all sorts of errors.

In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.

func (*ErrResponse) Error added in v1.0.9

func (e *ErrResponse) Error() string

func (*ErrResponse) Render added in v1.0.9

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

type Float

type Float float64

type FloatArray

type FloatArray []float64

type Int

type Int int64

type IntArray

type IntArray []int64

type ParamNames

type ParamNames struct {
	Fields         []string
	Search         []string
	Filter         []string
	Or             []string
	Join           []string
	Sort           []string
	Limit          []string
	Offset         []string
	Page           []string
	Cache          []string
	IncludeDeleted []string
}

type QueryFields

type QueryFields = []string

type QueryFilter

type QueryFilter struct {
	Field    string
	Operator ComparisonOperator
	Value    any
}

func (QueryFilter) String

func (f QueryFilter) String() string

type QueryJoin

type QueryJoin struct {
	Field  string
	Select QueryFields
}

func (QueryJoin) String

func (j QueryJoin) String() string

type QuerySort

type QuerySort struct {
	Field string
	Order QuerySortOperator
}

func (QuerySort) String

func (s QuerySort) String() string

type QuerySortOperator

type QuerySortOperator string
var (
	SORT_ASC  QuerySortOperator = "ASC"
	SORT_DESC QuerySortOperator = "DESC"
)

type RequestQuery

type RequestQuery struct {
	Fields         QueryFields
	ParamsFilter   []QueryFilter
	Search         SCondition
	Filter         []QueryFilter
	Or             []QueryFilter
	Join           []QueryJoin
	Sort           []QuerySort
	Limit          *int
	Offset         *int
	Page           *int
	Cache          *int
	IncludeDeleted *int
}

JsonQuery syntax: https://github.com/nestjsx/crud/wiki/Requests#query-params

func (*RequestQuery) ParseQuery

func (p *RequestQuery) ParseQuery(query url.Values) error
if err := r.ParseForm(); err != nil {
	return err
}

for k, v := range r.Form {

type RequestQueryBuilder

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

func NewRequestQueryBuilder

func NewRequestQueryBuilder() *RequestQueryBuilder

func NewRequestQueryBuilderFromParams

func NewRequestQueryBuilderFromParams(p CreateQueryParams) *RequestQueryBuilder

func (*RequestQueryBuilder) Query

func (rb *RequestQueryBuilder) Query() (string, error)

func (*RequestQueryBuilder) ResetCache

func (rb *RequestQueryBuilder) ResetCache() *RequestQueryBuilder

func (*RequestQueryBuilder) Search

func (*RequestQueryBuilder) Select

func (rb *RequestQueryBuilder) Select(fields ...string) *RequestQueryBuilder

func (*RequestQueryBuilder) SetFilter

func (*RequestQueryBuilder) SetIncludeDeleted

func (rb *RequestQueryBuilder) SetIncludeDeleted(n int) *RequestQueryBuilder

func (*RequestQueryBuilder) SetJoin

func (*RequestQueryBuilder) SetLimit

func (rb *RequestQueryBuilder) SetLimit(n int) *RequestQueryBuilder

func (*RequestQueryBuilder) SetOffset

func (rb *RequestQueryBuilder) SetOffset(n int) *RequestQueryBuilder

func (*RequestQueryBuilder) SetOr

func (*RequestQueryBuilder) SetPage

func (*RequestQueryBuilder) SortBy

func (*RequestQueryBuilder) UrlValues

func (rb *RequestQueryBuilder) UrlValues() (url.Values, error)

type SCondition

type SCondition interface {
	// contains filtered or unexported methods
}

type SCondition = SFields | SConditionAND;

func CAnd

func CAnd(ands ...SCondition) SCondition

func COr

func COr(ors ...SCondition) SCondition

type SConditionAND

type SConditionAND struct {
	And []SCondition `json:"$and,omitempty"`
}
type SConditionAND = {
	$and?: Array<SFields | SConditionAND>;
	$or?: never;
  }

type SField

type SField interface {
	// contains filtered or unexported methods
}

type SFieldOperator

type SFieldOperator struct {
	Eq      SFiledValues    `json:"$eq,omitempty"`
	Ne      SFiledValues    `json:"$ne,omitempty"`
	Gt      SFiledValues    `json:"$gt,omitempty"`
	Lt      SFiledValues    `json:"$lt,omitempty"`
	Gte     SFiledValues    `json:"$gte,omitempty"`
	Lte     SFiledValues    `json:"$lte,omitempty"`
	Starts  SFiledValues    `json:"$starts,omitempty"`
	Ends    SFiledValues    `json:"$ends,omitempty"`
	Cont    SFiledValues    `json:"$cont,omitempty"`
	Excl    SFiledValues    `json:"$excl,omitempty"`
	In      SFiledValues    `json:"$in,omitempty"`
	Notin   SFiledValues    `json:"$notin,omitempty"`
	Between SFiledValues    `json:"$between,omitempty"`
	Isnull  SFiledValues    `json:"$isnull,omitempty"`
	Notnull SFiledValues    `json:"$notnull,omitempty"`
	EqL     SFiledValues    `json:"$eqL,omitempty"`
	NeL     SFiledValues    `json:"$neL,omitempty"`
	StartsL SFiledValues    `json:"$startsL,omitempty"`
	EndsL   SFiledValues    `json:"$endsL,omitempty"`
	ContL   SFiledValues    `json:"$contL,omitempty"`
	ExclL   SFiledValues    `json:"$exclL,omitempty"`
	InL     SFiledValues    `json:"$inL,omitempty"`
	NotinL  SFiledValues    `json:"$notinL,omitempty"`
	Or      *SFieldOperator `json:"$or,omitempty"`
}

type SFields

type SFields map[string]interface{}

type SFiledValues

type SFiledValues interface {
	// contains filtered or unexported methods
}

type SPrimitivesVal

type SPrimitivesVal interface {
	// contains filtered or unexported methods
}

type String

type String string

type StringArray

type StringArray []string

Jump to

Keyboard shortcuts

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