Documentation
¶
Index ¶
- Variables
- func Close()
- type Connection
- func Open(logger ...*log.Logger) (Connection, error)
- func OpenEnv(env string, logger ...*log.Logger) (Connection, error)
- func OpenEnviron(e Environment, logger ...*log.Logger) (Connection, error)
- func OpenOnce(logger ...*log.Logger) (Connection, error)
- func OpenOnceEnv(env string, logger ...*log.Logger) (Connection, error)
- func OpenOnceEnviron(e Environment, logger ...*log.Logger) (Connection, error)
- func OpenWith(dbx *sqlx.DB, logger ...*log.Logger) (Connection, error)
- type Context
- type ContextFunc
- type Environment
- type MapMapper
- type QueryState
- type SliceMapper
- type Stmt
- type TxFunc
Constants ¶
This section is empty.
Variables ¶
var ( // Verbose is a global mode, when set at true, it will override the // configuration of the connections. Verbose bool // Debug is a global mode, when set at true, it will override the // configuration of the connections. Debug bool )
Functions ¶
Types ¶
type Connection ¶
type Connection interface {
DB() *sqlx.DB
Copy() Connection
Connect() error
LastError() error
Ping() error
MustPing()
Close() error
SetLogger(out *log.Logger, err *log.Logger)
// Statements
Exec(Stmt) (sql.Result, error)
// Queries
SelectMap(Stmt, MapMapper) (int, error)
SelectSlice(Stmt, SliceMapper) (int, error)
SelectMapRow(Stmt, MapMapper) (int, error)
SelectSliceRow(Stmt, SliceMapper) (int, error)
QueryMap(string, MapMapper, ...interface{}) (int, error)
QuerySlice(string, SliceMapper, ...interface{}) (int, error)
QueryMapRow(string, MapMapper, ...interface{}) (int, error)
QuerySliceRow(string, SliceMapper, ...interface{}) (int, error)
// Context
Context(...string) Connection
Done()
HasContext() bool
RunContext(...ContextFunc) error
// Tx
IsTx() bool
Tx(...sql.IsolationLevel) (Connection, error)
Commit() error
Rollback() error
RunTx(...TxFunc) error
}
Connection is a connection to an database.
func Open ¶
func Open(logger ...*log.Logger) (Connection, error)
Open opens a database from default environement.
func OpenEnv ¶
func OpenEnv(env string, logger ...*log.Logger) (Connection, error)
OpenEnv opens a database from given environment.
func OpenEnviron ¶
func OpenEnviron(e Environment, logger ...*log.Logger) (Connection, error)
OpenEnviron opens a database from a given environ.
func OpenOnce ¶
func OpenOnce(logger ...*log.Logger) (Connection, error)
OpenOnce opens a new connection or return the existing one.
func OpenOnceEnv ¶
func OpenOnceEnv(env string, logger ...*log.Logger) (Connection, error)
OpenOnceEnv opens a database from a given environment or return an existing one.
func OpenOnceEnviron ¶
func OpenOnceEnviron(e Environment, logger ...*log.Logger) (Connection, error)
OpenOnceEnviron opens a database from a given environ or return existing one.
type Context ¶
type Context interface {
ID() string
Done()
Flag() string
Len() int
Flush()
Err() error
Push(QueryState) bool
}
Context is the interface that abstract all interaction of the connection. Mainly used to bypass the unexported ctx.
type Environment ¶
type Environment struct {
Alias string
DSN string `env:"DATABASE_DSN"`
Driver string `env:"DATABASE_DRIVER"`
Protocol string `env:"DATABASE_PROTOCOL"`
Host string `env:"DATABASE_HOST"`
Port string `env:"DATABASE_PORT"`
User string `env:"DATABASE_USER"`
Pass string `env:"DATABASE_PASS" json:"-"`
Charset string `env:"DATABASE_CHARSET"`
Schema string `env:"DATABASE_SCHEMA"`
Mode string `env:"DATABASE_MODE"`
ParseTime bool `env:"DATABASE_PARSETIME"`
Autoconnect bool `env:"DATABASE_AUTOCONNECT"`
MaxOpen int `env:"DATABASE_MAXOPEN"`
MaxIdle int `env:"DATABASE_MAXIDLE"`
MaxLifetime time.Duration `env:"DATABASE_MAXLIFETIME"`
ProfilerEnable bool `env:"DATABASE_PROFILER_ENABLE"`
ProfilerOutput string `env:"DATABASE_PROFILER_OUTPUT"`
Verbose bool `env:"DATABASE_VERBOSE"`
Debug bool `env:"DATABASE_DEBUG"`
ErrorNoRows bool `env:"DATABASE_ERROR_NOROWS"`
}
Environment store the configuration to open a new connection.
func (*Environment) Boot ¶
func (e *Environment) Boot()
Boot load the default environment configuration.
func (*Environment) Load ¶
func (e *Environment) Load(alias string)
Load custom environment variable based on given alias.
func (*Environment) String ¶
func (e *Environment) String() string
String use the existing source or write a new one based on inputs.
func (*Environment) Validate ¶
func (e *Environment) Validate() error
Validate the environment configuration.
type MapMapper ¶
type MapMapper func(map[string]interface{})
MapMapper is the prototype to map a map result.
type QueryState ¶
type QueryState interface {
ContextID() string
ContextFlag() []string
Start() time.Time
End() time.Time
Runtime() time.Duration
String() string
Bytes() []byte
}
QueryState is the interface that abstract the state of the execution of an query.
type SliceMapper ¶
type SliceMapper func([]interface{})
SliceMapper is the prototype to map a slice result.