sqlxx

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: AGPL-3.0, AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNextSQLID

func GetNextSQLID() uint64

GetNextSQLID - запросить номер следующей SQL

Types

type Config

type Config struct {
	Name            string        `yaml:"name" json:"name"`                           // имя подключения
	ConnectString   string        `yaml:"-" json:"-"`                                 // строка подключения к БД
	Host            string        `yaml:"host" json:"host"`                           // host БД
	Port            string        `yaml:"port" json:"port"`                           // порт БД
	Dbname          string        `yaml:"dbname" json:"dbname"`                       // имя БД
	SslMode         string        `yaml:"ssl_mode" json:"ssl_mode"`                   // режим SSL
	User            string        `yaml:"user" json:"user"`                           // пользователь БД
	Pass            string        `yaml:"pass" json:"pass"`                           // пароль пользователя БД
	ConnMaxLifetime time.Duration `yaml:"conn_max_lifetime" json:"conn_max_lifetime"` // время жизни подключения в миллисекундах
	MaxOpenConns    int           `yaml:"max_open_conns" json:"max_open_conns"`       // максимальное количество открытых подключений
	MaxIdleConns    int           `yaml:"max_idle_conns" json:"max_idle_conns"`       // максимальное количество простаивающих подключений
	DriverName      string        `yaml:"driver_name" json:"driver_name"`             // имя драйвера "postgres" | "pgx" | "godror"
}

Config конфигурационные настройки БД

type DB

type DB struct {
	*sqlx.DB

	Name string
	// contains filtered or unexported fields
}

DB is a wrapper around sqlx.DB

func New

func New(cfg *Config, sqlStms SQLStms) (db *DB, myerr error)

New - create new connect to DB

func (*DB) BeginTxx

func (db *DB) BeginTxx(ctx context.Context, externalId uint64, opts *sql.TxOptions) (tx *Tx, myerr error)

BeginTxx - begin a new transaction

func (*DB) Beginx

func (db *DB) Beginx(externalId uint64) (tx *Tx, myerr error)

Beginx - begin a new transaction

func (*DB) Close

func (db *DB) Close() (myerr error)

Close - close DB

func (*DB) Commit

func (db *DB) Commit(externalId uint64, tx *Tx) (myerr error)

Commit - commit the transaction

func (*DB) Exec

func (db *DB) Exec(externalId uint64, tx *Tx, sqlT string, args ...interface{}) (rowsAffected int64, lastInsertId int64, err error)

Exec - represent common task in process DML statement

func (*DB) Get

func (db *DB) Get(externalId uint64, tx *Tx, sqlT string, dest interface{}, args ...interface{}) (exists bool, myerr error)

Get - represent common task in process SQL Select statement with only one rows

func (*DB) NamedExec

func (db *DB) NamedExec(externalId uint64, tx *Tx, sqlT string, args interface{}) (rowsAffected int64, lastInsertId int64, myerr error)

NamedExec - represent common task in process DML statement

func (*DB) PreparexAddSql

func (db *DB) PreparexAddSql(sql string, needPrepare bool) (myerr error)

PreparexAddSql - prepare SQL statements and add it to map

func (*DB) PreparexAll

func (db *DB) PreparexAll(sqlStms SQLStms) (myerr error)

PreparexAll - prepare SQL statements

func (*DB) QueryRowScan

func (db *DB) QueryRowScan(externalId uint64, tx *Tx, sqlT string, dest []interface{}, args ...interface{}) (exists bool, myerr error)

QueryRowScan - represent common task in process SQL Select statement with only one rows

func (*DB) QueryRowxStructScan

func (db *DB) QueryRowxStructScan(externalId uint64, tx *Tx, sqlT string, dest interface{}, args ...interface{}) (exists bool, myerr error)

QueryRowxStructScan - represent common task in process SQL Select statement with only one rows

func (*DB) Rollback

func (db *DB) Rollback(externalId uint64, tx *Tx) (myerr error)

Rollback - rollback the transaction

func (*DB) Select

func (db *DB) Select(externalId uint64, tx *Tx, sqlT string, dest interface{}, args ...interface{}) (myerr error)

Select - represent common task in process SQL Select statement

type SQLStm

type SQLStm struct {
	Text        string     // текст SQL команды
	Stmt        *sqlx.Stmt // подготовленная SQL команда
	NeedPrepare bool       // признак, нужно ли предварительно готовить SQL команду
}

SQLStm represent SQL text and sqlStm

type SQLStms

type SQLStms map[string]*SQLStm

SQLStms represent SQLStm map

type Tx

type Tx struct {
	*sqlx.Tx
}

Tx is an sqlx wrapper around sqlx.Tx

Jump to

Keyboard shortcuts

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