filter

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterData

func FilterData[T any](data *debefix.Data, tableID string, f func(row debefix.Row) (T, error),
	sortCompare func(T, T) int, options ...FilterDataOption) ([]T, error)

FilterData returns a filtered set of a single table of debefix.Data, converting a debefix.Row to a concrete type using generics. If sortCompare is not nil, the result is sorted with slices.SortFunc.

func FilterItemsToData added in v0.13.1

func FilterItemsToData[T any](items []FilterItem[T]) []T

FilterItemsToData returns only the data from a FilterItem.

Types

type FilterDataOption

type FilterDataOption func(*filterDataOptions)

func WithFilterAll

func WithFilterAll(filterAll bool) FilterDataOption

WithFilterAll include all records by default, depending on other filters if they exist. By default, if no filters were set, no record would be returned. Use this to return all rows in this case. All requested filters must return true to select the row.

func WithFilterFields

func WithFilterFields(fields map[string]any) FilterDataOption

WithFilterFields filters fields values. All requested filters must return true to select the row.

func WithFilterRefIDs

func WithFilterRefIDs(refIDs []string) FilterDataOption

WithFilterRefIDs filters by refID. All requested filters must return true to select the row.

func WithFilterRow

func WithFilterRow(filterRow func(row debefix.Row) (bool, error)) FilterDataOption

WithFilterRow filters using a callback. All requested filters must return true to select the row.

func WithOffsetLimit added in v0.11.0

func WithOffsetLimit(offset int, limit int) FilterDataOption

WithOffsetLimit filters the returning array from the offset, with limit amount of records.

type FilterDataRefIDItem added in v0.13.1

type FilterDataRefIDItem[T any] struct {
	Index int
	Data  T
}

type FilterDataRefIDResult added in v0.13.1

type FilterDataRefIDResult[T any] struct {
	Data          []T
	DataRefID     map[string]int
	MissingRefIDs []int
}

func FilterDataRefID added in v0.13.1

func FilterDataRefID[T any](data *debefix.Data, tableID string, f func(row debefix.Row) (T, error),
	sortCompare func(FilterItem[T], FilterItem[T]) int, options ...FilterDataOption) (FilterDataRefIDResult[T], error)

FilterDataRefID uses FilterDataRows to filter rows and in addition to returning the data, returns a map indexed by RefID of the items.

func (FilterDataRefIDResult[T]) RefID added in v0.13.2

func (r FilterDataRefIDResult[T]) RefID(refid string) (bool, T)

type FilterItem added in v0.13.1

type FilterItem[T any] struct {
	Item T
	Row  debefix.Row
}

FilterItem wraps the item returned by FilterData

func FilterDataRows added in v0.13.1

func FilterDataRows[T any](data *debefix.Data, tableID string, f func(row debefix.Row) (T, error),
	sortCompare func(FilterItem[T], FilterItem[T]) int, options ...FilterDataOption) ([]FilterItem[T], error)

FilterDataRows returns a filtered set of a single table of debefix.Data, converting a debefix.Row to a concrete type using generics, returning it together with the row. If sortCompare is not nil, the result is sorted with slices.SortFunc.

Jump to

Keyboard shortcuts

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