Documentation
¶
Index ¶
- func Mapper(row *sql.Rows, model reflect.Type) (obj interface{}, err error)
- type CreateConnection
- type DBContextFunction
- type DBContextWithTransactionFunction
- type DBFieldMapping
- type Database
- type DbContext
- func (context *DbContext) ExecuteQuery(query string, params ...interface{}) error
- func (context *DbContext) First(rows []interface{}) interface{}
- func (context *DbContext) GetConnection() (*sql.DB, error)
- func (context *DbContext) GetListener(channel string) (*Listener, error)
- func (context *DbContext) GetRows(query string, mapping DBFieldMapping, params ...interface{}) (data []interface{}, err error)
- func (context *DbContext) GetRowsModel(query string, model reflect.Type, params ...interface{}) (data []interface{}, err error)
- func (context *DbContext) GetSingleRow(query string, mapping DBFieldMapping, params ...interface{}) (data interface{}, err error)
- func (context *DbContext) GetSingleRowModel(query string, model reflect.Type, params ...interface{}) (data interface{}, err error)
- func (context *DbContext) Mapper(model reflect.Type) DBFieldMapping
- func (context *DbContext) Mapping(rows *sql.Rows, mapping DBFieldMapping) (data []interface{}, err error)
- func (context *DbContext) Setup(host string, port int, user, password, db, sslMode string, poolSize *int, ...)
- func (context *DbContext) Using(query DBContextFunction) error
- func (context *DbContext) UsingWithTransaction(query DBContextWithTransactionFunction) error
- type IDbContext
- type Listener
- type Pool
- type PoolConnection
- type QueryExecutor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CreateConnection ¶
CreateConnection - Function for create connection
type DBContextFunction ¶
DBContextFunction - Callback function for receiving db connection
type DBContextWithTransactionFunction ¶
DBContextWithTransactionFunction - Callback function for receiving db transaction
type DBFieldMapping ¶
DBFieldMapping - Callback function for apply field mapping
type Database ¶
type Database struct {
DbContext
Host string `yaml:"host"`
Port int `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Db string `yaml:"db"`
SslMode *string `yaml:"sslMode"`
PoolSize *int `yaml:"poolSize"`
}
func (*Database) HealthCheck ¶
func (*Database) HealthCode ¶
func (*Database) HealthName ¶
type DbContext ¶
type DbContext struct {
IDbContext
// contains filtered or unexported fields
}
DbContext - db context
func (*DbContext) ExecuteQuery ¶
ExecuteQuery - execute query
func (*DbContext) First ¶
func (context *DbContext) First(rows []interface{}) interface{}
First - return firs item from list
func (*DbContext) GetConnection ¶
GetConnection - get connection for DB
func (*DbContext) GetListener ¶
GetListener - get listener
func (*DbContext) GetRows ¶
func (context *DbContext) GetRows(query string, mapping DBFieldMapping, params ...interface{}) (data []interface{}, err error)
GetRows - execute query what return list rows
func (*DbContext) GetRowsModel ¶
func (context *DbContext) GetRowsModel(query string, model reflect.Type, params ...interface{}) (data []interface{}, err error)
GetRowsModel - execute query what return list rows with model
func (*DbContext) GetSingleRow ¶
func (context *DbContext) GetSingleRow(query string, mapping DBFieldMapping, params ...interface{}) (data interface{}, err error)
GetSingleRow - execute query what return only one row
func (*DbContext) GetSingleRowModel ¶
func (context *DbContext) GetSingleRowModel(query string, model reflect.Type, params ...interface{}) (data interface{}, err error)
GetSingleRowModel - execute query what return only one row with model
func (*DbContext) Mapper ¶
func (context *DbContext) Mapper(model reflect.Type) DBFieldMapping
Mapper - define rule for mapping sql row to model
func (*DbContext) Mapping ¶
func (context *DbContext) Mapping(rows *sql.Rows, mapping DBFieldMapping) (data []interface{}, err error)
Mapping - mapping sql row to model collection
func (*DbContext) Setup ¶
func (context *DbContext) Setup(host string, port int, user, password, db, sslMode string, poolSize *int, timeLife *time.Duration)
Setup - setup Db context
func (*DbContext) Using ¶
func (context *DbContext) Using(query DBContextFunction) error
Using - helper for execute query with connection
func (*DbContext) UsingWithTransaction ¶
func (context *DbContext) UsingWithTransaction(query DBContextWithTransactionFunction) error
UsingWithTransaction - helper for execute query with transaction
type IDbContext ¶
type IDbContext interface {
// Setup - setup Db context
Setup(host string, port int, user, password, db, sslMode string, poolSize *int,
timeLife *time.Duration)
// GetConnection - Get connection for DB
GetConnection() (*sql.DB, error)
// Using - helper for execute query with connection
Using(query DBContextFunction) error
// UsingWithTransaction - helper for execute query with transaction
UsingWithTransaction(query DBContextWithTransactionFunction) error
// GetRows - execute query what return list rows
GetRows(query string, mapping DBFieldMapping, params ...interface{}) (data []interface{}, err error)
// GetRowsModel - execute query what return list rows with model
GetRowsModel(query string, model reflect.Type, params ...interface{}) (data []interface{}, err error)
// GetSingleRow - execute query what return only one row
GetSingleRow(query string, mapping DBFieldMapping, params ...interface{}) (data interface{}, err error)
// GetSingleRowModel: execute query what return only one row with model
GetSingleRowModel(query string, model reflect.Type, params ...interface{}) (data interface{}, err error)
// ExecuteQuery - execute query
ExecuteQuery(query string, params ...interface{}) error
}
IDbContext - DB context common interface
type Listener ¶
type Listener struct {
Data chan string
// contains filtered or unexported fields
}
Listener - class for work with Postgres listener
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool - pool of db connection
type PoolConnection ¶
type PoolConnection struct {
CreateTime time.Time // time of creation
// contains filtered or unexported fields
}
PoolConnection - connection in pool