query

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

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) AddFilterRequest
func (qb *Builder) AddFilterRequest(request *filter.Request) error

AddFilterRequest 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. TODO: Enhance the AddFilterRequest function to prevent SQL injection vulnerabilities. AddFilterRequest is currently vulnerable to sql injection and should be used only when the input is trusted

func (*Builder) AddPaging
func (qb *Builder) AddPaging(paging *paging.Request) error

AddPaging appends paging conditions to the query builder based on the provided paging request. It constructs the OFFSET and LIMIT clauses according to the specified page index and page size.

func (*Builder) AddSorting
func (qb *Builder) AddSorting(sort *sorting.Request) error

AddSorting appends sorting conditions to the query builder based on the provided sorting request. It constructs the ORDER BY clause using the specified sort column and direction.

func (*Builder) Build
func (qb *Builder) Build(resultSelector query.ResultSelector) string

Build generates the complete SQL query based on the provided result selector. It constructs the query by adding filter, sorting, and paging conditions. If any error occurs during the construction, it returns an empty string.

type Settings

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

type Settings struct {
    FilterFieldMapping map[string]string // Mapping of filter fields for query customization
}

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) AddFilterRequest

func (qb *Builder) AddFilterRequest(request *filter.Request) error

AddFilterRequest 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. TODO: Enhance the AddFilterRequest function to prevent SQL injection vulnerabilities. AddFilterRequest is currently vulnerable to sql injection and should be used only when the input is trusted

func (*Builder) AddPaging

func (qb *Builder) AddPaging(paging *paging.Request) error

AddPaging appends paging conditions to the query builder based on the provided paging request. It constructs the OFFSET and LIMIT clauses according to the specified page index and page size.

func (*Builder) AddSorting

func (qb *Builder) AddSorting(sort *sorting.Request) error

AddSorting appends sorting conditions to the query builder based on the provided sorting request. It constructs the ORDER BY clause using the specified sort column and direction.

func (*Builder) Build

func (qb *Builder) Build(resultSelector query.ResultSelector) string

Build generates the complete SQL query based on the provided result selector. It constructs the query by adding filter, sorting, and paging conditions. If any error occurs during the construction, it returns an empty string.

type Settings

type Settings struct {
	FilterFieldMapping map[string]string // Mapping of filter fields for query customization
}

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