db

package
v0.0.0-...-46fca04 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT, MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(sourceURL string, retries int) (*sqlx.DB, error)

Types

type Config

type Config struct {
	SourceURL             string
	Retries               int
	MaxOpenConnections    int
	MaxIdleConnections    int
	ConnectionMaxLifetime time.Duration
}

type DB

type DB struct {
	Instance *sqlx.DB
}

func New

func New(cfg Config) (*DB, error)

func (*DB) ExecContect

func (db *DB) ExecContect(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*DB) Get

func (db *DB) Get(ctx context.Context, query string, param GetDBParam, target interface{}) error

func (*DB) GetWithCount

func (db *DB) GetWithCount(ctx context.Context, mainQuery, countQuery string, param GetDBParam, target interface{}, totalRecord *int) error

func (*DB) QueryRowxContext

func (db *DB) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row

type Filter

type Filter struct {
	Field    string
	Value    interface{}
	Operator Operator
}

type GetDBParam

type GetDBParam struct {
	Search       Search
	Filters      []Filter
	Sorts        []Sort
	Limit        int
	Offset       int
	DisableGet   bool
	DisableCount bool
	// contains filtered or unexported fields
}

func (GetDBParam) GetQuery

func (g GetDBParam) GetQuery(query string) (string, []interface{})

WhereQuery enable where query

func (GetDBParam) SortQuery

func (g GetDBParam) SortQuery() GetDBParam

SortQuery enable sorting. returned args always empty

func (GetDBParam) WhereQuery

func (g GetDBParam) WhereQuery() GetDBParam

WhereQuery enable where query

type Operator

type Operator string
const (
	NotNullOp          Operator = "IS NOT NULL"
	IsNullOp           Operator = "IS NULL"
	EqualOp            Operator = "="
	NotEqualOp         Operator = "<>"
	GreaterThanOp      Operator = ">"
	LowerThanOp        Operator = "<"
	GreaterThanEqualOp Operator = ">="
	LowerThanEqualOp   Operator = "<="
)
type Search struct {
	Query  string
	Fields []string
}

type Sort

type Sort struct {
	Order int
	Field string
	Asc   bool
}

Jump to

Keyboard shortcuts

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