querybuilder

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCondition

func BuildCondition(query *gorm.DB, field string, criteria interface{}) *gorm.DB

BuildCondition is the builder for the provided WebPageCriteria, it also supports the usage of LIKE statements without needing the extra %

func ParseAndPreloadAssociations

func ParseAndPreloadAssociations(query *gorm.DB, associations string) (*gorm.DB, error)

ParseAndPreloadAssociations is there as a helper to preload specific tables that the user Would like to be exported. If the "all" parameter is specified, it will exporters all the models

Types

type QueryBuilder

type QueryBuilder struct {
	// WebPageCriteria is a map that accepts different fields.
	//It takes in key value pairs. You can also specify the LIKE keyword like this:
	//title: LIKE example
	WebPageCriteria map[string]interface{}
	// Associations - pryingtools, Email, Crypto, etc.
	// E.G only email if only email is specified, there will be no crypto records, they will be set to null.
	Associations string

	SortBy    string
	SortOrder string
	Limit     int
	// Offset represents the number of records that get skipped during export.
	Offset int
}

QueryBuilder stores SQL parameters that are used for performing gorm SQL statements.

func NewQueryBuilder

func NewQueryBuilder(webPageCriteria map[string]interface{}, associations, sortBy, sortOrder string, limit int, offset int) *QueryBuilder

NewQueryBuilder returns a pointer to the QueryBuilder struct

func (*QueryBuilder) ConstructQuery

func (qb *QueryBuilder) ConstructQuery(db *gorm.DB) []models.WebPage

ConstructQuery (ConstructQuery) Constructs the queries based on the fields

func (*QueryBuilder) Raw

func (qb *QueryBuilder) Raw(db *gorm.DB, relativePath string) (error, []map[string]interface{})

Raw is a helper for executing raw queries inside the database. You can define Your query anywhere you want and call this method to execute custom queries Note: This will not provide structured keys like ConstructQuery. However, this function does give you more control on what fields you can choose from other models and export them later on. This function also does not support INSERT statements.

Jump to

Keyboard shortcuts

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