dbx

package module
v0.0.0-...-c4d2788 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2018 License: MIT Imports: 16 Imported by: 0

README

  • TODO:
  • Tests
  • Documentation

Documentation

Index

Constants

View Source
const (
	MysqlDriver    = "mysql"
	PgxDriver      = "pgx"
	PostgresDriver = "postgres"
)
View Source
const (
	LevelSlowQuery = "SLOW_QUERY"
	LevelDebug     = "DEBUG"
	LevelError     = "ERROR"
)
View Source
const (
	LogError = 1 << iota
	LogDebug
	LogSLow

	DefaultSlowLogMin = 1 * time.Second
)

Variables

This section is empty.

Functions

func BuildInsertParams

func BuildInsertParams(m map[string]interface{}, rowIt int, params []string, values []interface{}) string

func DropTestDB

func DropTestDB(cfg *Config) error

func ReturningAll

func ReturningAll(query string) string

func ReturningCustom

func ReturningCustom(query string, fields []string) string

func ReturningID

func ReturningID(query string) string

func SetEnvPrefix

func SetEnvPrefix(pref string)

func WithOptions

func WithOptions(option []QueryOption, query string, args ...interface{}) (string, []interface{})

Types

type Config

type Config struct {
	Ssl    bool   `mapstructure:"ssl"`
	Driver string `mapstructure:"driver"`

	Host string `yaml:"host" mapstructure:"host"`
	Port int    `mapstructure:"port"`

	DBName   string `mapstructure:"db_name"`
	User     string `mapstructure:"user"`
	Password string `mapstructure:"password"`

	DoLog             bool
	LogDir            string
	SlowQueryDuration time.Duration
	// contains filtered or unexported fields
}

DBConfig holds the configuration parameters of main DB connection

func LoadConfigFromEnv

func LoadConfigFromEnv(configPrefix string) (*Config, error)

func LoadConfigFromFile

func LoadConfigFromFile(cfgKey string, configType string, configName string, configPaths ...string) (*Config, error)

type DBX

type DBX struct {
	// contains filtered or unexported fields
}

func New

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

New creates an instance of *DBX for specified driver (mysql, pgx)

func NewTest

func NewTest(cfg *Config) (*DBX, error)

NewTest creates an instance of *DBX especially for test Multiple checks are done to ensure we are not working on the live data Configuration can either be passed as an argument, or retrieved from the environment variables. If none were set, default values are used.

func (*DBX) Close

func (dbx *DBX) Close() error

func (*DBX) Exec

func (dbx *DBX) Exec(query string, args ...interface{}) (sql.Result, error)

func (*DBX) MustBegin

func (dbx *DBX) MustBegin() *Tx

func (*DBX) NamedExec

func (dbx *DBX) NamedExec(query string, arg interface{}) (sql.Result, error)

func (*DBX) NamedInsert

func (dbx *DBX) NamedInsert(target interface{}, tableName string, paramNames []string, m map[string]interface{}) (string, []interface{}, error)

func (*DBX) NamedSelect

func (dbx *DBX) NamedSelect(dest interface{}, query string, arg interface{}) error

func (*DBX) QueryRowx

func (dbx *DBX) QueryRowx(query string, args ...interface{}) *sqlx.Row

func (*DBX) Queryx

func (dbx *DBX) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)

func (*DBX) Rebind

func (dbx *DBX) Rebind(query string) string

func (*DBX) Select

func (dbx *DBX) Select(dest interface{}, query string, args ...interface{}) error

func (*DBX) SetLogger

func (dbx *DBX) SetLogger(logType int8, out io.Writer) error

func (*DBX) SetLoggerAsync

func (dbx *DBX) SetLoggerAsync(async bool)

func (*DBX) SetMaxIdleConns

func (dbx *DBX) SetMaxIdleConns(n int)

func (*DBX) SetMaxOpenConns

func (dbx *DBX) SetMaxOpenConns(n int)

func (*DBX) SetSlowLogMin

func (dbx *DBX) SetSlowLogMin(minDur time.Duration)

func (*DBX) SkipLog

func (dbx *DBX) SkipLog()

func (*DBX) Unsafe

func (dbx *DBX) Unsafe() *DBX

type EmptySliceErr

type EmptySliceErr struct {
	// contains filtered or unexported fields
}

func (*EmptySliceErr) Error

func (e *EmptySliceErr) Error() string

type MissingParamErr

type MissingParamErr struct {
	// contains filtered or unexported fields
}

func (*MissingParamErr) Error

func (e *MissingParamErr) Error() string

type NilPointerErr

type NilPointerErr struct {
	// contains filtered or unexported fields
}

func (*NilPointerErr) Error

func (e *NilPointerErr) Error() string

type Querier

type Querier interface {
	Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
	QueryRowx(query string, args ...interface{}) *sqlx.Row
	Select(dest interface{}, query string, args ...interface{}) error
	Exec(query string, args ...interface{}) (sql.Result, error)
	NamedExec(query string, arg interface{}) (sql.Result, error)
	Rebind(query string) string
}

type Querierx

type Querierx interface {
	Querier
	NamedInsert(target interface{}, tableName string, params []string, arg map[string]interface{}) (string, []interface{}, error)
	NamedSelect(dest interface{}, query string, arg interface{}) error
	SkipLog()
}

type QueryOption

type QueryOption struct {
	// contains filtered or unexported fields
}

func NewOffsetOption

func NewOffsetOption(offset int, limit int) QueryOption

func NewPageOption

func NewPageOption(page int, length int) QueryOption

func (QueryOption) IncOffset

func (qo QueryOption) IncOffset(inc int)

func (QueryOption) IncPage

func (qo QueryOption) IncPage(inc int)

func (QueryOption) Page

func (qo QueryOption) Page() int

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

func (*Tx) Commit

func (tx *Tx) Commit() error

func (*Tx) Exec

func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error)

func (*Tx) NamedExec

func (tx *Tx) NamedExec(query string, arg interface{}) (sql.Result, error)

func (*Tx) NamedInsert

func (tx *Tx) NamedInsert(target interface{}, tableName string, paramNames []string, m map[string]interface{}) (string, []interface{}, error)

func (*Tx) NamedSelect

func (tx *Tx) NamedSelect(dest interface{}, query string, arg interface{}) error

func (*Tx) QueryRowx

func (tx *Tx) QueryRowx(query string, args ...interface{}) *sqlx.Row

func (*Tx) Queryx

func (tx *Tx) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)

func (*Tx) Rebind

func (tx *Tx) Rebind(query string) string

func (*Tx) Rollback

func (tx *Tx) Rollback() error

func (*Tx) Select

func (tx *Tx) Select(dest interface{}, query string, args ...interface{}) error

func (*Tx) SkipLog

func (tx *Tx) SkipLog()

func (*Tx) Unsafe

func (tx *Tx) Unsafe() *Tx

type WrongTypeErr

type WrongTypeErr struct {
	// contains filtered or unexported fields
}

func (*WrongTypeErr) Error

func (e *WrongTypeErr) Error() string

Jump to

Keyboard shortcuts

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