builder

package
v0.0.0-...-8f64e43 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IFilterBuilder

type IFilterBuilder interface {
	// SetFields sets the list of fields for the filter.
	SetFields(fields []field.IFilterField) IFilterBuilder

	// AddFields adds a list of fields to the filter.
	AddFields(fields []field.IFilterField) IFilterBuilder

	// AddField adds a new field to the filter.
	AddField(field field.IFilterField) IFilterBuilder

	// GetFields returns a list of all fields.
	GetFields() []field.IFilterField

	// GetFieldByIndex returns a field by its index.
	GetFieldByIndex(index int) field.IFilterField

	// GetFieldsByName returns a list of fields if their names match the provided one.
	GetFieldsByName(name string) []field.IFilterField

	// RemoveField removes a field from the filter.
	RemoveField(field field.IFilterField) IFilterBuilder

	// RemoveFieldByIndex removes a field from the filter by its index.
	RemoveFieldByIndex(index int) IFilterBuilder

	// RemoveFieldByName removes a field from the filter by its name.
	RemoveFieldByName(name string) IFilterBuilder

	// MergeDuplicateFields merges duplicate fields into a single field
	MergeDuplicateFields() IFilterBuilder

	// Build is used to build bson filter for mongodb based on provided struct.
	Build() IFilterBuilder

	// Output returns the final bson.D object
	Output() bson.D
}

IFilterBuilder is used to build bson filter for mongodb based on provided struct. Its main responsibility is to construct a proper bson.D from provided struct by scanning each field of the struct, storing them in a list and then merging them into a single bson.D object. It also provides convenience methods like add/remove fields. To confirm to SRP, it delegates the responsibility of scanning struct fields to IScanner and the responsibility of building bson.D from each field to IFilterField

func NewFilterBuilder

func NewFilterBuilder() IFilterBuilder

NewFilterBuilder creates a new instance of IFilterBuilder

Jump to

Keyboard shortcuts

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