Documentation
¶
Overview ¶
Package struql helps to filter data in the structure, presenting it as a table.
Typical usage
type detail struct {
Id int32
Value string
}
type device struct {
Number int
Model string
Details []detail
}
var dev = device{
Number: 1,
Model: "OEM",
Details: []detail{
{Id: 1, Value: "First"},
{Id: 2, Value: "Soul"},
{Id: 3, Value: "Seven"},
},
}
var sq struql.StruQL
sq.Init(dev)
filter := []struql.Filter{
{
FieldName: "Details.Id",
Value: int32(1),
Operation: struql.ComparisonGreater
},
{
FieldName: "Details.Value",
Value: "S",
Operation: struql.ComparisonBeginWith
},
}
dataSet := make(struql.RowCollection, 1)
dataSet, _ = sq.Where(dataSet, filter...)
values, _ := dataSet.CollectValues("Details.Id")
fmt.Printf("Details.Id: %v\n", vals)
Index ¶
- Constants
- type Field
- type Filter
- type Row
- type RowCollection
- func (r RowCollection) AddField(name string, value interface{})
- func (r RowCollection) CollectValues(fieldName string) ([]interface{}, error)
- func (r RowCollection) Count() int
- func (r RowCollection) String() string
- func (r RowCollection) Where(result RowCollection, filters ...Filter) (RowCollection, error)
- type StruQL
- type ValueModifier
Constants ¶
const ( // ComparisonEqual - = ComparisonEqual = iota // ComparisonNotEqual - != ComparisonNotEqual // ComparisonIn - field in [values] ComparisonIn // ComparisonGreater - > ComparisonGreater // ComparisonLesser - < ComparisonLesser // ComparisonBeginWith - field like 'value%' ComparisonBeginWith // ComparisonEndWith - field like '%value' ComparisonEndWith // ComparisonExists - value in[field values] ComparisonExists )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct {
Name string
Value interface{}
// contains filtered or unexported fields
}
Field represents struct field in the table
type Filter ¶
type Filter struct {
FieldName string
Value interface{}
Operation int
Modifier ValueModifier
// contains filtered or unexported fields
}
Filter sets the search condition
type Row ¶
type Row struct {
// contains filtered or unexported fields
}
Row - collection of fields / table row
func (*Row) FieldByIndex ¶
FieldByIndex returns field by it's index or nil
func (*Row) FieldByName ¶
FieldByName returns field by it's name or nil
type RowCollection ¶
type RowCollection []*Row
RowCollection - collection of rows / table
func (RowCollection) AddField ¶
func (r RowCollection) AddField(name string, value interface{})
AddField add field to all rows
func (RowCollection) CollectValues ¶
func (r RowCollection) CollectValues(fieldName string) ([]interface{}, error)
CollectValues returns array of values of according field
func (RowCollection) String ¶
func (r RowCollection) String() string
String represents rows as string
func (RowCollection) Where ¶
func (r RowCollection) Where(result RowCollection, filters ...Filter) (RowCollection, error)
Where collects data in the rows according to filters
type StruQL ¶
type StruQL struct {
Rows RowCollection
// contains filtered or unexported fields
}
StruQL implements struct to table transforming algorithm
func (*StruQL) Where ¶
func (s *StruQL) Where(result RowCollection, filters ...Filter) (RowCollection, error)
Where collects data in the rows according to filters
type ValueModifier ¶
type ValueModifier func(Value interface{}) interface{}
ValueModifier - callback for transforming field value before compare