# README
query
import "github.com/greenbone/opensight-golang-libraries/pkg/postgres/query"
Package query facilitates the translation of a result selector into a PostgresSQL conditional query string, incorporating sorting and paging functionalities.
Index
type Builder
Builder represents a query builder used to construct PostgresSQL conditional query strings with sorting and paging functionalities.
type Builder struct {
// contains filtered or unexported fields
}
func NewPostgresQueryBuilder
func NewPostgresQueryBuilder(querySetting *Settings) *Builder
NewPostgresQueryBuilder creates a new instance of the query builder with the provided settings.
func (*Builder) Build
func (qb *Builder) Build(resultSelector query.ResultSelector) (query string, args []any, err error)
Build generates the complete SQL query based on the provided result selector. It constructs the query by adding filter, sorting, and paging conditions. It returns the constructed query string, and all the individual filter fields values (args) in a single list If any error occurs during the construction, it returns an empty string.
func (*Builder) BuildQueryConditions
func (qb *Builder) BuildQueryConditions(request *filter.Request) (args []any, err error)
BuildQueryConditions builds and appends filter conditions to the query builder based on the provided filter request. It constructs conditional clauses using the logic operator specified in the request. It uses the `?` query placeholder, so you can pass your parameter separately It returns all individual field values in a single list BuildQueryConditions can be used as a standalone function with Gorm
type Settings
Settings is a configuration struct used to customize the behavior of the query builder.
type Settings struct {
// FilterFieldMapping is the mapping of filter fields for query customization
// also serves as safeguard against sql injection
FilterFieldMapping map[string]string
}
Generated by gomarkdoc