database

package
v0.0.0-...-ca0f7d1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const MigrationsTableName = "migrations"

Variables

View Source
var (
	ErrRepositoryNoRowsAffected  = errors.New("no rows affected")
	ErrRepositoryNoEntitiesFound = errors.New("no entities found")
	ErrRepositoryEntityExists    = errors.New("entity exists")
)
View Source
var (
	// ErrDBConnAttemptsFailed ошибка для случаев невозможности подключения к БД
	ErrDBConnAttemptsFailed = errors.New("All attempts to connect db failed")
)

Functions

func Exec

func Exec(executor QueryExecutor, queryBuilder QueryBuilder) error

func ExecWithCaller

func ExecWithCaller(caller string, executor QueryExecutor, queryBuilder QueryBuilder) error

func GetRawFieldName

func GetRawFieldName(fieldName string) string

func Query

func Query(executor QueryExecutor,
	queryBuilder QueryBuilder,
	scanFunc func(rows *sql.Rows) error,
) error

func QueryRow

func QueryRow(executor QueryExecutor, queryBuilder QueryBuilder) (*sql.Row, error)

func QueryRowWithCaller

func QueryRowWithCaller(caller string, executor QueryExecutor, queryBuilder QueryBuilder) (*sql.Row, error)

func QueryWithCaller

func QueryWithCaller(
	caller string,
	executor QueryExecutor,
	queryBuilder QueryBuilder,
	scanFunc func(rows *sql.Rows) error,
) error

func RunWithTransaction

func RunWithTransaction(db *sql.DB, callerName string, function func(tx *sql.Tx) error) error

Types

type Database

type Database struct {
	Logger log.Interface
	// contains filtered or unexported fields
}

Database - компонент для подключения к БД

func New

func New(dsn string, maxOpenConns int, logger log.Interface) (*Database, error)

New инициализирует подключение к БД

func (*Database) Check

func (d *Database) Check() health.Health

Check возвращает состояние подключения к базе

func (*Database) Close

func (d *Database) Close() error

Close закрывает соединение с БД

func (*Database) DB

func (d *Database) DB() *sql.DB

DB возвращает указатель на коннект к БД

func (*Database) WatchConnection

func (d *Database) WatchConnection(errChan chan<- error)

WatchConnection вешает watcher на соединение с базой и в случае ошибки с ним - рестартит ее

type QueryBuilder

type QueryBuilder interface {
	ToSql() (string, []interface{}, error)
}

type QueryExecutor

type QueryExecutor interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
}

type RowScanner

type RowScanner interface {
	Scan(destination ...interface{}) error
}

type RowsScanner

type RowsScanner interface {
	Scan(destination ...interface{}) error
	Err() error
	Next() bool
}

Jump to

Keyboard shortcuts

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