gormhelper

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const EXCEPT = "EXCEPT:"
View Source
const MYSQL = "mysql"
View Source
const NO_JOIN = "NO_JOIN"
View Source
const ONLY_JOIN = "ONLY_JOIN"
View Source
const ONLY_PRELOAD = "ONLY_PRELOAD"
View Source
const POSTGRES = "postgres"
View Source
const SQLITE = "sqlite"

Variables

This section is empty.

Functions

func CrossInnerJoin

func CrossInnerJoin[T any, J any, U comparable, K comparable](
	getMainStructs func(derivedIds []K, isFirstGet bool) ([]T, error),
	getDerivedId func(mainStruct T) U,
	getDerivedStructs func(ids []U) (derivedStructs []J, err error),
	getMainId func(derivedStruct J) K,
	filterUnusedDerivedStruct *func(derivedStruct J, ids []U) bool,
	setDerived func(mainStruct *T, derivedStruct J) (nextMain bool),
) ([]T, error)

use for join by different db getDerivedStructs shouldn't return paginated result encourage to sort according given ids in getDerivedStructs, it will improve processing speed because inner join so getMainStructs will run 2 times and second time will return derivedIds to filter again filterUnusedDerivedStruct is used to relief stress of nested loop filterUnusedDerivedStruct can just simply return true or function below func(derivedStruct J, ids []U) { arrayhelper.Includes(ids, derivedStruct.<fk>) }

func CrossJoin

func CrossJoin[T any, J any, U comparable](
	mainStructs []T,
	getDerivedId func(mainStruct T) U,
	getDerivedStructs func(ids []U) (derivedStructs []J, err error),
	setDerived func(mainStruct *T, derivedStruct J) (nextMain bool),
) ([]T, error)

use for join by different db getDerivedStructs shouldn't return paginated result encourage to sort according given ids in getDerivedStructs, it will improve processing speed

func GetQuote

func GetQuote(db *gorm.DB) string

func IsNotFound

func IsNotFound(err error) bool

func Join

func Join(db *gorm.DB, joinMap, preloadMap map[string][]interface{}, joinStrings ...string) *gorm.DB

func Select

func Select(
	db *gorm.DB,
	model interface{},
	oriTableName string,
	oriPreFix string,
	sumList []string,
	ignoreList []string,
	targetTableName string,
	targetPrefix string,
	targetPostfix string,
	customList []string,
	needSort bool) []string

oriPreFix: can use for prefix ori table name (e.x: oriPreFix = "data_baidu" become select `data_baidu`.xx)

Types

This section is empty.

Jump to

Keyboard shortcuts

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