search

package
v0.0.0-...-a0d0b40 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2016 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewThingCountHandler

func NewThingCountHandler(db *sqlx.DB) gin.HandlerFunc

NewThingCountHandler will return a handler for ThingSearchRequests.

The handler assumes that the ThingSearchRequest will be POSTed using JSON.

func NewThingGetByIDHandler

func NewThingGetByIDHandler(db *sqlx.DB) gin.HandlerFunc

NewThingGetByIDHandler will return a handler for Thing GET requests.

The handler assumes that you have constructed a GET route with a path param of `:id` (i.e. `/api/v1/:id`) for the ID and also that the ID field of Thing is called ID.

func NewThingSearchHandler

func NewThingSearchHandler(db *sqlx.DB) gin.HandlerFunc

NewThingSearchHandler will return a handler for ThingSearchRequests.

The handler assumes that the ThingSearchRequest will be POSTed using JSON.

Types

type SQLThingSearcher

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

SQLThingSearcher implements a SQL based searcher

func (*SQLThingSearcher) Count

func (r *SQLThingSearcher) Count(searchRequest ThingSearchRequest) (int32, error)

Count converts a ThingSearchRequest in to SQL and executes it

func (*SQLThingSearcher) GetByField

func (r *SQLThingSearcher) GetByField(field ThingField, value interface{}) (*types.Thing, error)

GetByField is a convenience method to return just one result by matching on a single field

func (*SQLThingSearcher) Search

func (r *SQLThingSearcher) Search(searchRequest ThingSearchRequest) ([]types.Thing, error)

Search converts a ThingSearchRequest in to SQL and executes it

type ThingField

type ThingField int

ThingField is a field within the Thing struct that is able to be filtered on, sorted on, or returned.

const (
	ThingID ThingField = iota
	ThingColor
	ThingDescription
	ThingLength
	ThingHeight
)

Enum'd for helpfulness

func (ThingField) DbFieldName

func (s ThingField) DbFieldName() string

DbFieldName returns the name of the field to use in the SQL query

func (ThingField) MarshalText

func (s ThingField) MarshalText() ([]byte, error)

MarshalText implements https://golang.org/pkg/encoding/#TextMarshaler

func (*ThingField) UnmarshalText

func (s *ThingField) UnmarshalText(b []byte) error

UnmarshalText implements https://golang.org/pkg/encoding/#TextUnmarshaler

type ThingOrderBy

type ThingOrderBy struct {
	Field      ThingField `json:"field"`
	Descending bool       `json:"desc"`
}

ThingOrderBy is a sort directive that is specific to Thing

type ThingSearchFilter

type ThingSearchFilter struct {
	Field     ThingField               `json:"field"`
	Value     interface{}              `json:"value"`
	Operator  searcher.FilterOperator  `json:"operator"`
	Condition searcher.FilterCondition `json:"condition"`
}

ThingSearchFilter is a filter specific to Thing

type ThingSearchRequest

type ThingSearchRequest struct {
	searcher.SearchRequestFields
	Filters []ThingSearchFilter `json:"filters"`
	OrderBy ThingOrderBy        `json:"orderBy"`
	Fields  []ThingField        `json:"fields"`
}

ThingSearchRequest defines a set of parameters for searching for Thing. It can be serialized and passed between services as JSON, or used to generate a SQL statement.

func (*ThingSearchRequest) AddFilter

func (sr *ThingSearchRequest) AddFilter(field ThingField, value interface{}, operator searcher.FilterOperator, condition searcher.FilterCondition)

AddFilter adds a WHERE clause

func (*ThingSearchRequest) GetFields

func (sr *ThingSearchRequest) GetFields() []string

GetFields returns the SQL SELECT fields

func (*ThingSearchRequest) GetFilters

func (sr *ThingSearchRequest) GetFilters() []searcher.Filter

GetFilters returns the SQL WHERE clauses

func (*ThingSearchRequest) GetLimit

func (sr *ThingSearchRequest) GetLimit() int

GetLimit returns the SQL LIMIT clause

func (*ThingSearchRequest) GetOffset

func (sr *ThingSearchRequest) GetOffset() int

GetOffset returns the SQL OFFSET clause

func (*ThingSearchRequest) GetOrderBy

func (sr *ThingSearchRequest) GetOrderBy() searcher.OrderBy

GetOrderBy returns the SQL ORDER BY clauses

func (*ThingSearchRequest) GetTableName

func (sr *ThingSearchRequest) GetTableName() string

GetTableName returns the database table name

func (*ThingSearchRequest) SetOrderBy

func (sr *ThingSearchRequest) SetOrderBy(field ThingField, isDescending bool)

SetOrderBy sets the ORDER BY clause

type ThingSearcher

type ThingSearcher interface {
	Search(searchRequest ThingSearchRequest) ([]types.Thing, error)
	Count(searchRequest ThingSearchRequest) (int32, error)
	GetByField(field ThingField, value interface{}) (*types.Thing, error)
}

ThingSearcher is the interface

func NewSQLThingSearcher

func NewSQLThingSearcher(db *sqlx.DB) ThingSearcher

NewSQLThingSearcher returns a configured repo for you

Jump to

Keyboard shortcuts

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