Filters

2025-09-08 11:41:13  Updated

Filter types

  • ObTableFilterList: connects different filters.
  • ObTableValueFilter: compares values.
  • ObTableInFilter/ObTableNotInFilter: checks whether the selected column value is equal to any of the values in the collection.

ObTableFilterList

This filter connects different filters by using And or Or.

The syntax is as follows:

const (
    OperatorAnd Operator = iota
    OperatorOr
)

You can use a function to obtain a filter list connected by And or Or. The syntax is as follows:

func AndList(filters ...ObTableFilter) *ObTableFilterList {
    return NewObTableFilterListWithOperatorAndTableFilter(OperatorAnd, filters...)
}

func OrList(filters ...ObTableFilter) *ObTableFilterList {
    return NewObTableFilterListWithOperatorAndTableFilter(OperatorOr, filters...)
}

ObTableValueFilter

This filter is the most basic filter used to check whether the values of a column meet the specified conditions. The columns that meet the specified conditions are chosen.

The syntax is as follows:

const (
    LessThan ObCompareOperator = iota
    GreaterThan
    LessOrEqualThan
    GreaterOrEqualThan
    NotEqual
    Equal
    IsNull
    IsNotNull
)

func CompareVal(op ObCompareOperator, columnName string, value interface{}) *ObTableValueFilter {
    return NewObTableValueFilter(op, columnName, value)
}

Input parameters:

  • op: defines the method for comparison between column names and values, which is contained in the value of const.
  • columnName: the column name for comparison.
  • value: the value to be compared with the column name.

ObTableInFilter/ObTableNotInFilter

The syntax is as follows:

func In(columnName string, values ...interface{}) *ObTableInFilter {
    return NewObTableInFilter(columnName, values...)
}

func NotIn(columnName string, values ...interface{}) *ObTableNotInFilter {
    return NewObTableNotInFilter(columnName, values...)
}

Input parameters:

  • columnName: the column name for comparison.
  • values: the values to be compared with the column name. ObTableInFilter checks whether the column name is equal to any of the values. ObTableNotInFilter checks whether the column name is not equal to any of the values. The values of the column are not included in values.

Example

// 4 < c1 < 6
c1lt6 := filter.CompareVal(filter.LessThan, "c1", int64(6))
c1gt4 := filter.CompareVal(filter.GreaterThan, "c1", int64(4))
c1filterList := filter.AndList(c1lt6, c1gt4)

// 0 >= c2 or c2 >= 2
c2le0 := filter.CompareVal(filter.LessOrEqualThan, "c2", int64(0))
c2ge2 := filter.CompareVal(filter.GreaterOrEqualThan, "c2", int64(2))
c2filterList := filter.orList(c2le0, c2ge2)

// (4 < c1 < 6 ) && (c2 <= 0) && (c2 >= 2)
finalFilter := filter.AndList(c1filterList, c2filterList)

Contact Us