Documentation ¶
Index ¶
- Variables
- type Config
- type DBSQL
- func (d *DBSQL) Close() error
- func (d *DBSQL) Exec(query string, args ...interface{}) (int64, error)
- func (d *DBSQL) Get(dest interface{}, query string, args ...interface{}) error
- func (d *DBSQL) GetMap(query string, args ...interface{}) (ret map[string]interface{}, err error)
- func (d *DBSQL) NamedExec(query string, arg interface{}) (int64, error)
- func (d *DBSQL) NamedGet(dest interface{}, query string, arg interface{}) error
- func (d *DBSQL) NamedGetMap(query string, arg interface{}) (ret map[string]interface{}, err error)
- func (d *DBSQL) NamedSelect(dest interface{}, query string, arg interface{}) error
- func (d *DBSQL) NamedSelectMaps(query string, arg interface{}) (ret []map[string]interface{}, err error)
- func (d *DBSQL) Select(dest interface{}, query string, args ...interface{}) error
- func (d *DBSQL) SelectMaps(query string, args ...interface{}) (ret []map[string]interface{}, err error)
- func (d *DBSQL) SetTimeout(timeout uint)
Constants ¶
This section is empty.
Variables ¶
var ErrBadConfigDB = errors.New("не заполнены параметры подключения к БД")
ErrBadConfigDB ошибка
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Host string `yaml:"host" env:"DB_HOST" env-required:"true"` Port int `yaml:"port" env:"DB_PORT" env-default:"1433" env-description:"sql server port"` User string `yaml:"user" env:"DB_USER" env-required:"true"` Password string `yaml:"password" env:"DB_PASSWORD" env-required:"true"` Database string `yaml:"database" env:"DB_DATABASE" env-required:"true"` TimeoutQuery int `yaml:"timeout_query" env:"TIMEOUT_QUERY" env-default:"300"` // Second APPName string `yaml:"app_name" env:"APP_NAME"` DriverName string `yaml:"driver_name" env:"DRIVER_NAME" env-default:"sqlserver"` }
Config структура для параметров соединения с БД
func (*Config) GetDatabaseURL ¶
GetDatabaseURL "sqlserver://user:password@host:port?database=database_name" "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable" "mysql://username:password@protocol(address)/dbname?param=value" "user:password@tcp(127.0.0.1:3306)/sql_test?charset=utf8mb4&parseTime=True" sqlite3 или имя БД или :memory: driver sqlserver || postgres
func (*Config) WithDriverName ¶
WithDriverName задания наименования драйвера БД
func (*Config) WithPassword ¶
WithPassword установка пароля
type DBSQL ¶
DBSQL ...
func (*DBSQL) NamedGetMap ¶
NamedGetMap ...
func (*DBSQL) NamedSelect ¶
NamedSelect получаем данные из запроса в слайс структур
var users []User
err := ts.db.NamedSelect(&users, "select * from users where name=:Name", map[string]interface{}{"Name": "admin"})
func (*DBSQL) NamedSelectMaps ¶
func (d *DBSQL) NamedSelectMaps(query string, arg interface{}) (ret []map[string]interface{}, err error)
NamedSelectMaps ...
func (*DBSQL) Select ¶
Select получаем данные из запроса в слайс структур
var users []User
err := ts.db.Select(&users, "select * from users")
func (*DBSQL) SelectMaps ¶
func (d *DBSQL) SelectMaps(query string, args ...interface{}) (ret []map[string]interface{}, err error)
SelectMaps ...
func (*DBSQL) SetTimeout ¶
SetTimeout установка таймаута для выполнения запроса в секундах