postgres

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DisableSSL    = "disable"
	RequireSSL    = "require"
	VerifyCASSL   = "verify-ca"
	VerifyFullSSL = "verify-full"
)

SSL mod

Variables

This section is empty.

Functions

This section is empty.

Types

type IPgDB

type IPgDB interface {
	GetDB() *sqlx.DB
	ExecuteQuery(string, string, ...interface{}) (*sql.Rows, error)
	ExecuteRowAffected(string, string, ...interface{}) (int64, error)
	ExecuteQueryX(string, string, ...interface{}) (*sqlx.Rows, error)
	Select(string, interface{}, string, ...interface{}) error
	Get(string, interface{}, string, ...interface{}) error
	NamedExec(string, string, map[string]interface{}) (sql.Result, error)
	NamedQuery(string, string, interface{}) (*sqlx.Rows, error)
}

IPgDB - public interface describes PgDB

type PgDB

type PgDB struct {
	Name string // Name DB (better uniq id in program)

	URL    string // Domain name (localhost - default)
	Host   string // Hostname domain (IP)
	Port   int    // Port Db (Postgres 5432)
	DbName string // Db name (main)

	SSL string // SSL mod (disable/enable)  @see https://godoc.org/github.com/lib/pq
	// * disable - No SSL * require - Always SSL (skip verification) * verify-ca - Always SSL * verify-full - Always SSL
	SSLCert     string // sslcert Cert file location. The file must contain PEM encoded data.
	SSLKey      string // sslkey Key file location. The file must contain PEM encoded data.
	SSLRootCert string // sslrootcert The location of the root certificate file. The file

	User string // The user to sign in as
	Pass string // The user's password

	CntAttemptRequest  int  // Cnt attempts connect to DB
	TimeAttemptRequest int  // Time between attempts  ! SECONDS !
	RepeatRequest      bool // Cnt try repeat execute SQL request to DB
	ConnMaxLifetime    int  // time in Nanosecond
	MaxIdleConns       int  // max idle connections
	MaxOpenConns       int  // max open connections

	Email  *email.MailBean // Email Bean for send error info
	Logger l.LoggerI       // Pointer to Logger interface
	// contains filtered or unexported fields
}

PgDB - Bean for work with Postgres DB

func (*PgDB) Close

func (pg *PgDB) Close()

Close - Закрытие соединения

func (*PgDB) ConfigString

func (pg *PgDB) ConfigString() (config string)

ConfigString - config connect DB

func (*PgDB) Connect

func (pg *PgDB) Connect() (err error)

Connect - Создание пула коннекшенов к БД

func (*PgDB) ExecuteQuery

func (pg *PgDB) ExecuteQuery(callBy string, query string, args ...interface{}) (rows *sql.Rows, err error)

ExecuteQuery - Функция обертка над execute. Запросы с ожиданием данных от БД. (SELECT и т.д. возращающие значения)

func (*PgDB) ExecuteQueryX

func (pg *PgDB) ExecuteQueryX(callBy string, query string, args ...interface{}) (rows *sqlx.Rows, err error)

ExecuteQueryX - Функция обертка над QueryX (sqlX). Запросы с ожиданием данных от БД.

func (*PgDB) ExecuteRowAffected

func (pg *PgDB) ExecuteRowAffected(callBy string, query string, args ...interface{}) (rowAffected int64, err error)

ExecuteRowAffected - Функция обертка над Execute. Запрос без ожидания данных, с ожиданием кол-ва затронутых строк.

func (*PgDB) Get

func (pg *PgDB) Get(callBy string, dest interface{}, query string, args ...interface{}) (err error)

Get - syntax sugar of `SELECT ... LIMIT 1` method; @param

   callBy       string      - кто вызвал, важно для логирования, чтобы не вызывать runtime.Caller()
   dest         interface   - интерфейс указатель куда запишем данные
   query        string      - строка SQL запрос
   args...      interface{} - аргументы
@return
                error       - есть ли ошибка в запросе

func (*PgDB) GetDB

func (pg *PgDB) GetDB() *sqlx.DB

GetDB - get current DB connect

func (*PgDB) GetName

func (pg *PgDB) GetName() string

GetName - get Name obj DB

func (*PgDB) NamedExec

func (pg *PgDB) NamedExec(callBy string, query string, nameArgs map[string]interface{}) (result sql.Result, err error)

NamedExec - syntax sugar of sql.NamedExec `INSERT INTO person (first_name,last_name,email) VALUES (:first,:last,:email)`,;

map[string]interface{}{
           "first": "Bin",
           "last": "Smuth",
           "email": "bensmith@allblacks.nz",

@param

   callBy       string                 - кто вызвал, важно для логирования, чтобы не вызывать runtime.Caller()
   query        string                 - строка SQL запрос
   nameArgs     map[string]interface{} - map с именнованными аргументами
@return
                sql.Result  - результаты запроса
                error       - есть ли ошибка в запросе

func (*PgDB) NamedQuery

func (pg *PgDB) NamedQuery(callBy string, query string, data interface{}) (rows *sqlx.Rows, err error)

NamedQuery - syntax sugar of sql.NamedQuery `SELECT * FROM person WHERE first_name=:first_name`, jason`,; @param

   callBy       string      - кто вызвал, важно для логирования, чтобы не вызывать runtime.Caller()
   query        string      - строка SQL запрос
   data         interface{} - map с именнованными аргументами
@return
                *sqlx.Rows  - результаты зароса строки
                error       - есть ли ошибка в запросе

func (*PgDB) Select

func (pg *PgDB) Select(callBy string, dest interface{}, query string, args ...interface{}) (err error)

Select - syntax sugar of `SELECT ... ` method; @param

   callBy       string      - кто вызвал, важно для логирования, чтобы не вызывать runtime.Caller()
   dest         interface   - интерфейс указатель куда запишем данные
   query        string      - строка SQL запрос
   args...      interface{} - аргументы
@return
                error       - есть ли ошибка в запросе

Jump to

Keyboard shortcuts

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