query

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: GPL-3.0 Imports: 9 Imported by: 1

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

Documentation

Overview

Package query facilitates the translation of a result selector into a PostgresSQL conditional query string, incorporating sorting and paging functionalities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder represents a query builder used to construct PostgresSQL conditional query strings with sorting and paging functionalities.

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 added in v1.7.3

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

type Settings struct {
	// FilterFieldMapping is the mapping of filter fields for query customization
	// also serves as safeguard against sql injection
	FilterFieldMapping map[string]string
}

Settings is a configuration struct used to customize the behavior of the query builder.

Jump to

Keyboard shortcuts

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