pgxhelper

package module
v1.0.1 Latest Latest
Warning

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

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

README

PGX-Helper

PGX-Helper is a simple package for creating sql queries with dynamic structure.

Documentation

Index

Constants

View Source
const (
	OPR_EQUAL     = "="
	OPR_NOT_EQUAL = "!="
	OPR_IN        = "IN"
	OPR_ANY       = "ANY"
	OPR_GTE       = ">="
	OPR_GT        = ">"
	OPR_LTE       = "<="
	OPR_LT        = "<"
	OPR_LIKE      = "ILIKE"
	OPR_NOT_LIKE  = "NOT ILIKE"
	OPR_IS        = "IS"
	OPR_IS_NOT    = "IS NOT"
	OPR_IS_NULL   = "_NULL_"
)

Variables

View Source
var (
	ErrDuplicateKey = fmt.Errorf("DUPLICATE KEY")
	ErrNotFound     = fmt.Errorf("NOT FOUND")
)

Functions

This section is empty.

Types

type Condition

type Condition struct {
	ColumnName string
	Operator   string
	Value      any
}

type ConditionGroup

type ConditionGroup struct {
	Join       Joiner
	Conditions []*Condition
}

type Config

type Config struct {
	Host     string
	Port     string
	User     string
	Password string
	DBName   string
	SslMode  string
	Timezone string
}

func (Config) MakeDSN

func (c Config) MakeDSN() string

type DBConfig

type DBConfig interface {
	MakeDSN() string
}

func GetConfigFromEnv

func GetConfigFromEnv() (DBConfig, error)

func GetConfigFromEnvOption added in v0.0.5

func GetConfigFromEnvOption(keys *KeysConfig) (DBConfig, error)

type DatabaseHelper

type DatabaseHelper struct {
	Pool *pgxpool.Pool
}

func (*DatabaseHelper) AddSort added in v0.0.13

func (dh *DatabaseHelper) AddSort(sort *Sort) (query string)

func (*DatabaseHelper) BuildDynamicQuery added in v0.0.7

func (dh *DatabaseHelper) BuildDynamicQuery(values *[]any, opts []*ConditionGroup) string

func (*DatabaseHelper) Exec

func (dh *DatabaseHelper) Exec(ctx context.Context, query string, values ...any) error

func (*DatabaseHelper) Exist

func (dh *DatabaseHelper) Exist(ctx context.Context, table string, condition string, values ...any) (bool, error)

func (*DatabaseHelper) MakeTx

func (dh *DatabaseHelper) MakeTx(ctx context.Context) (pgx.Tx, func(err error) error, error)

func (*DatabaseHelper) Query

func (dh *DatabaseHelper) Query(ctx context.Context, scanner Scanner, query string, values ...any) error

type Dir added in v0.0.13

type Dir string
var (
	DirAscending  Dir = "ASC"
	DirDescending Dir = "DESC"
)

type Joiner

type Joiner = string
const (
	JOINER_AND Joiner = " AND "
	JOINER_OR  Joiner = " OR "
)

type KeysConfig added in v0.0.5

type KeysConfig struct {
	Host     string
	Port     string
	User     string
	Password string
	Name     string
	SslMode  string
	Timezone string
}

type Scanner

type Scanner = func(row pgx.Row) error

type Sort added in v0.0.13

type Sort struct {
	Column    string
	Direction Dir
}

Jump to

Keyboard shortcuts

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