dbw

package module
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 18 Imported by: 1

README

dbw

sql/database wrapper

Documentation

Index

Constants

View Source
const (
	// TagNoSeq запрещает генерацию значения для поля ID, если поле типа int
	// используя последовательность tablename_SEQ.
	TagNoSeq = "noseq"

	// TagNoIns исключает поле при вставке.
	TagNoIns = "noins"

	// TagNoUpd исключает поле при Update
	TagNoUpd = "noupd"

	// TagNoCache исключает поле при чтении записей функцией DoSelectCache().
	TagNoCache = "nocache"
)
View Source
const (
	ValidateLen int = iota << 1
	ValidateNotNull
	ValidateIntRange
)

Variables

View Source
var (
	ErrUniqueViolation         = errors.New("unique violation").StatusCode(409)
	ErrCheckConstaintViolation = errors.New("check constraint violation").StatusCode(400)
	ErrConnectionDone          = errors.New("database connection lost").StatusCode(503).Critical()
	ErrQueryExecFailed         = errors.New("query execution failed").StatusCode(500).Critical()
	ErrNotFound                = errors.New("not found").StatusCode(404)
)
View Source
var AutoCheckTableExistance bool = true

AutoCheckTableExistance checks existance of table in NewTable() call.

View Source
var ErrUnknownPreparedStatement = errors.New("unknown prepared statement")
View Source
var FieldTagLabel = "dbw"

FieldTagLabel содержит наименование тэга используемого в аннотациях к атрибутам структуры.

View Source
var PrimaryKeyFieldName = "ID"

Functions

func Append

func Append(arr interface{}, elem interface{}) error

Append appends elem into arr array.

func BindTables

func BindTables(ctx context.Context, db *DB, tt map[string]TableDesc, parallel bool) map[string]error

BindTables

func FieldAddrs

func FieldAddrs(model interface{}, excludeTag string) []interface{}

fieldAddrs returns slice of pointers to struct's fields excluding fields having tag value specified in excludeTag

func FieldNames

func FieldNames(model interface{}, tagRules string) string

FieldNames returns names of struct fields separated by comma. Includes anonymous structs as well.

func HasAutoincrementFieldID

func HasAutoincrementFieldID(model interface{}) bool

HasAutoincrementFieldID returns true if struct has field ID with one of type: int8, int16, int32, int64 and has no tag "noseq".

func MaskPostgreSQLConnectionString added in v0.4.0

func MaskPostgreSQLConnectionString(src string) string

MaskPostgreSQLConnectionString replaces password=12345 by password=*****.

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase converts string like RobertEgorov to robert_egorov.

func WithCols added in v0.2.3

func WithCols(cv map[string]interface{}) func(*Option)

func WithCtx added in v0.2.0

func WithCtx(ctx context.Context) func(*Option)

func WithID added in v0.2.3

func WithID(val interface{}) func(*Option)

func WithIgnoreConflict added in v0.2.0

func WithIgnoreConflict(text string) func(*Option)

func WithIgnoreConflictColumn added in v0.2.3

func WithIgnoreConflictColumn(column ...string) func(*Option)

func WithReturnAll added in v0.2.3

func WithReturnAll(dst interface{}) func(*Option)

func WithReturnDeletedAt added in v0.2.3

func WithReturnDeletedAt(dst interface{}) func(*Option)

func WithReturnID added in v0.2.3

func WithReturnID(dst interface{}) func(*Option)

func WithReturnVersion added in v0.2.3

func WithReturnVersion(dst interface{}) func(*Option)

func WithRow added in v0.2.3

func WithRow(row interface{}) func(*Option)

func WithTag added in v0.2.3

func WithTag(tag string, rule TagExclusionRule) func(*Option)

func WithTx added in v0.2.0

func WithTx(tx *Tx) func(*Option)

func WithWhere added in v0.2.3

func WithWhere(cond string, val ...interface{}) func(*Option)

func WithoutReturnAll added in v0.2.3

func WithoutReturnAll() func(*Option)

func WrapError

func WrapError(t interface{}, err error, params ...interface{}) error

func WrapErrorOld

func WrapErrorOld(t interface{}, err error, params ...interface{}) error

WrapError .

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB wraps database/sql for better performance and logging. PostgreSQL RDBMS is supported only.

func Inherit

func Inherit(db *sql.DB) *DB

Inherit creates DB object using already existing sql.DB object.

func Open

func Open(driverName, dataSourceName string) (*DB, error)

Open tries once to establish connection to database.

func RepetableOpen

func RepetableOpen(ctx context.Context, driverName, dataSourceName string, l *zerolog.Logger, aff func(string, int, error) time.Duration) (*DB, error)

RepetableOpen tries to establish connection to database till ctx.Done() or success. It calls func aff() after every failed attempt.

func (*DB) Begin

func (db *DB) Begin() *Tx

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) *Tx

func (*DB) CleanUnusedStatement

func (db *DB) CleanUnusedStatement(d time.Duration)

CleanUnusedStatement deletes prepared statements not used last d.

func (*DB) Close

func (db *DB) Close() error

func (*DB) Exec

func (db *DB) Exec(qry string, args ...interface{}) (sql.Result, error)

func (*DB) ExecContext

func (db *DB) ExecContext(ctx context.Context, qry string, args ...interface{}) (sql.Result, error)

func (*DB) ExecContextTx

func (db *DB) ExecContextTx(ctx context.Context, tx *Tx, qry string, args ...interface{}) (sql.Result, error)

func (*DB) ExecTx

func (db *DB) ExecTx(tx *Tx, qry string, args ...interface{}) (sql.Result, error)

func (*DB) InTx added in v0.1.0

func (db *DB) InTx(f func(*Tx) error) error

func (*DB) Logger

func (db *DB) Logger() *zerolog.Logger

func (*DB) Ping

func (db *DB) Ping() error

func (*DB) PingContext

func (db *DB) PingContext(ctx context.Context) error

func (*DB) PlaceHolderType

func (db *DB) PlaceHolderType() ParamPlaceHolderType

func (*DB) Prepare

func (db *DB) Prepare(qry string) *Stmt

Prepare prepares SQL statement. Unique statement name is hash generated.

func (*DB) PrepareContext

func (db *DB) PrepareContext(ctx context.Context, qry string) *Stmt

PrepareContext prepares SQL statement. Unique statement name is hash generated.

func (*DB) PrepareContextN

func (db *DB) PrepareContextN(ctx context.Context, qry, uid string) *Stmt

PrepareNamed prepared statement referenced by unique name. Later, prepared statement can be taken from cache by uid. It's expected that SQL parameters are always used for performance reasons.

func (*DB) PrepareN

func (db *DB) PrepareN(qry, uid string) *Stmt

PrepareN prepares SQL statement. Parameter uid holds user defined unique statement name.

func (*DB) PreparedStatementCount

func (db *DB) PreparedStatementCount() int

func (*DB) Query

func (db *DB) Query(qry string, args ...interface{}) *StmtInstance

func (*DB) QueryContext

func (db *DB) QueryContext(ctx context.Context, qry string, args ...interface{}) *StmtInstance

func (*DB) QueryContextTx

func (db *DB) QueryContextTx(ctx context.Context, tx *Tx, qry string, args ...interface{}) *StmtInstance

func (*DB) QueryRow

func (db *DB) QueryRow(qry string, args ...interface{}) *StmtInstance

func (*DB) QueryRowContext

func (db *DB) QueryRowContext(ctx context.Context, qry string, args ...interface{}) *StmtInstance

func (*DB) QueryRowContextTx

func (db *DB) QueryRowContextTx(ctx context.Context, tx *Tx, qry string, args ...interface{}) *StmtInstance

func (*DB) QueryRowTx

func (db *DB) QueryRowTx(tx *Tx, qry string, args ...interface{}) *StmtInstance

func (*DB) QueryTx

func (db *DB) QueryTx(tx *Tx, qry string, args ...interface{}) *StmtInstance

func (*DB) SQLDB

func (db *DB) SQLDB() *sql.DB

func (*DB) SetLogger

func (db *DB) SetLogger(l *zerolog.Logger)

func (*DB) SetPlaceHolderType

func (db *DB) SetPlaceHolderType(ph ParamPlaceHolderType)

func (*DB) Stmt

func (db *DB) Stmt(uid string) (*Stmt, bool)

type DefaultStmtLogger

type DefaultStmtLogger struct {
}

func NewDefaultStmtLogger

func NewDefaultStmtLogger() *DefaultStmtLogger

func (*DefaultStmtLogger) After

func (dsl *DefaultStmtLogger) After(sli *StmtInstance)

func (*DefaultStmtLogger) ArgsFormat

func (dsl *DefaultStmtLogger) ArgsFormat(args ...interface{}) string

func (*DefaultStmtLogger) Before

func (dsl *DefaultStmtLogger) Before(sli *StmtInstance)

func (*DefaultStmtLogger) ContextFormat

func (dsl *DefaultStmtLogger) ContextFormat(ctx context.Context) string

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error describes error raising by SQL queries related to a single table represented by *Table or by arbitrary SQL query.

func (Error) Error

func (e Error) Error() string

func (Error) MarshalZerologObject

func (err Error) MarshalZerologObject(e *zerolog.Event)

func (*Error) SQLErrCode

func (e *Error) SQLErrCode() string

type NullString

type NullString string

NullString defines types for nullable varchar column without additional "Valid bool" attributes.

func (NullString) MarshalJSON

func (ns NullString) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json Marshaller interface.

func (NullString) MarshalText

func (ns NullString) MarshalText(b []byte) ([]byte, error)

MarshalText implements encoding/text TextMarshaller interface.

func (*NullString) Scan

func (ns *NullString) Scan(value interface{}) error

Scan implements database/sql Scanner interface.

func (NullString) String

func (ns NullString) String() string

String returns string representation of value.

func (*NullString) UnmarshalJSON

func (ns *NullString) UnmarshalJSON(b []byte) error

UnmarshalJSON implements encoding/json Unmarshaller interface.

func (*NullString) UnmarshalText

func (ns *NullString) UnmarshalText(b []byte) error

UnmarshalText implements encoding/text TextUnmarshaller interface.

func (NullString) Valid

func (ns NullString) Valid() bool

Valid return true if value is not empty or false, if len==0.

func (NullString) Value

func (ns NullString) Value() (driver.Value, error)

Value implements interface sql.Valuer

type NullTime

type NullTime time.Time

NullTime defines types for nullable varchar column without additional "Valid bool" attributes.

func FieldAddrsUpdate

func FieldAddrsUpdate(model interface{}, excludeTag string) (res []interface{}, updatedAt *NullTime, rowVersion *int)

func (NullTime) MarshalJSON added in v0.2.1

func (ns NullTime) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json Marshaller interface.

func (NullTime) MarshalText added in v0.2.1

func (ns NullTime) MarshalText(b []byte) ([]byte, error)

MarshalText implements encoding/text TextMarshaller interface.

func (*NullTime) Scan

func (ns *NullTime) Scan(value interface{}) error

Scan implements database/sql Scanner interface.

func (*NullTime) SetNow

func (ns *NullTime) SetNow()

func (NullTime) String

func (ns NullTime) String() string

String returns string representation of value.

func (*NullTime) UnmarshalJSON added in v0.2.1

func (ns *NullTime) UnmarshalJSON(b []byte) error

UnmarshalJSON implements encoding/json Unmarshaller interface.

func (*NullTime) UnmarshalText added in v0.2.1

func (ns *NullTime) UnmarshalText(b []byte) error

UnmarshalText implements encoding/text TextUnmarshaller interface.

func (NullTime) Valid

func (ns NullTime) Valid() bool

Valid return true if value is not empty or false, if len==0.

func (NullTime) Value

func (ns NullTime) Value() (driver.Value, error)

Value implements interface sql.Valuer

type Option added in v0.2.0

type Option struct {
	// contains filtered or unexported fields
}

type ParamPlaceHolderType

type ParamPlaceHolderType int

ParamPlaceHolderType определяет тип плейсхолдера для переменных запроса.

const (
	// QuestionMark - вопросительный знак.
	QuestionMark ParamPlaceHolderType = iota
	// DollarPlusPosition - знак доллара и номер позиции.
	DollarPlusPosition
)

type RowValidationResult

type RowValidationResult map[string]int

type Sequence

type Sequence struct {
	// contains filtered or unexported fields
}

Sequence describes database object sequence and provides method to generate next value.

Important: An object must not be used with tables column ID (int?) with no tag "noseq". Because for this table value generates automatically.

func NewSequence

func NewSequence(db *DB, name string) *Sequence

NewSequence creates Sequence object.

func (*Sequence) CheckExistance

func (s *Sequence) CheckExistance() error

CheckExistance checks sequence existance.

func (*Sequence) NextVal

func (s *Sequence) NextVal(ctx context.Context) (int64, error)

NextVal returns next sequence value.

type Stmt

type Stmt struct {
	// contains filtered or unexported fields
}

func (*Stmt) Close

func (ss *Stmt) Close() error

func (*Stmt) DB

func (s *Stmt) DB() *DB

func (*Stmt) Err

func (s *Stmt) Err() error

func (*Stmt) Instance

func (s *Stmt) Instance() *StmtInstance

func (*Stmt) InstanceTx

func (s *Stmt) InstanceTx(tx *Tx) *StmtInstance

func (*Stmt) LastInstanceUnixTime

func (s *Stmt) LastInstanceUnixTime() int64

func (*Stmt) Text

func (s *Stmt) Text() string

func (*Stmt) UID

func (s *Stmt) UID() string

type StmtInstance

type StmtInstance struct {

	// At holds time when instance created (sent to database).
	At time.Time

	// RespondedIn holds duration between At and moment when 1st row retrived.
	RespondedIn time.Duration

	// RowsFetched holds numner or rows fetched by SELECT.
	RowsFetched int

	// RowsFetchedIn holds duration between getting 1st and last rows.
	RowsFetchedIn time.Duration

	// QueryParams holds SQL query parameters.
	QueryParams string

	// CtxParams holds context/session related parameters.
	CtxParams string

	// Num holds SQL statement sequential number since application start.
	Num uint64
	// contains filtered or unexported fields
}

StmtInstance

func (*StmtInstance) Close

func (si *StmtInstance) Close() error

Close closes statement instance with preserving error if was exist.

func (*StmtInstance) Debug

func (si *StmtInstance) Debug() *StmtInstance

func (*StmtInstance) Err

func (si *StmtInstance) Err() error

func (*StmtInstance) Exec

func (si *StmtInstance) Exec(args ...interface{}) (sql.Result, error)

Exec executes SQL command represented by StmtInstance. A SQL command does not return any values.

func (*StmtInstance) ExecContext

func (si *StmtInstance) ExecContext(ctx context.Context, args ...interface{}) (sql.Result, error)

ExecContext executes SQL command what not returns data back.

func (*StmtInstance) Fetch

func (si *StmtInstance) Fetch(f func() error, dest ...interface{}) *StmtInstance

ScanAll

func (*StmtInstance) FetchAll

func (si *StmtInstance) FetchAll(arr interface{}, row interface{}, dest ...interface{}) *StmtInstance

FetchAll automatically stores fetched rows into the slice arr.

func (*StmtInstance) Query

func (si *StmtInstance) Query(args ...interface{}) *StmtInstance

func (*StmtInstance) QueryContext

func (si *StmtInstance) QueryContext(ctx context.Context, args ...interface{}) *StmtInstance

func (*StmtInstance) QueryRow

func (si *StmtInstance) QueryRow(args ...interface{}) *StmtInstance

func (*StmtInstance) QueryRowContext

func (si *StmtInstance) QueryRowContext(ctx context.Context, args ...interface{}) *StmtInstance

func (*StmtInstance) QueryRowTx

func (si *StmtInstance) QueryRowTx(tx *Tx, ctx context.Context, args ...interface{}) *StmtInstance

func (*StmtInstance) Scan

func (si *StmtInstance) Scan(dest ...interface{}) error

Scan read values from database driver to dest.

func (*StmtInstance) Tx

func (si *StmtInstance) Tx() *Tx

func (*StmtInstance) ViaTx

func (si *StmtInstance) ViaTx(tx *Tx) *StmtInstance

type StmtLogger

type StmtLogger interface {
	// New(s Statementer, ctx context.Context, qparams string) *StmtInstance
	// NewTx(tx *Tx, s Statementer, ctx context.Context, qparams string) *StmtInstance
	Before(*StmtInstance)
	After(*StmtInstance)
	ContextFormat(ctx context.Context) string
	ArgsFormat(args ...interface{}) string
}

type Table

type Table struct {
	SQL struct {
		SelectCache               string
		SelectCacheWithoutDeleted string
		Select                    string
		BasicInsert               string
		Insert                    string
		BasicUpdate               string
		HardDelete                string
		SoftDelete                string
		ExistByID                 string
		ExistByUID                string
		UpdateRowVersion          string
		SelectByID                string
		FlexDelete                string
		SelectCount               string
	}
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, db *DB, name string, model interface{}) (*Table, error)

New automatically recognises autoincrement using sequecne by existance of field ID with type int? If there is no autoicrement requrements set tag "noseq". It extected, that sequence used for autoincrement has "tablename_seq".

func NewTable

func NewTable(db *DB, name string, model interface{}) *Table

func (*Table) CheckColumns

func (t *Table) CheckColumns() error

func (*Table) CheckTableExistance

func (t *Table) CheckTableExistance() error

func (*Table) ColTags

func (t *Table) ColTags() string

func (*Table) Columns added in v0.3.0

func (t *Table) Columns() string

func (*Table) Count

func (t *Table) Count(where string, params ...interface{}) (int, error)

Count returns amount of rows in the table complaints with condition in where.

func (*Table) DB

func (t *Table) DB() *DB

func (*Table) Delete added in v0.2.3

func (t *Table) Delete(optFunc ...func(*Option)) error

func (*Table) DoHardDel

func (t *Table) DoHardDel(where string, args ...interface{}) (sql.Result, error)

DoHardDel deletes row completely using condition described in where.

func (*Table) DoHardDelTx

func (t *Table) DoHardDelTx(tx *Tx, where string, args ...interface{}) (sql.Result, error)

DoHardDelTx deletes row completely using condition described in where in a transaction.

func (*Table) DoHardDelete

func (t *Table) DoHardDelete(id interface{}) error

DoHardDelete deletes row completely.

func (*Table) DoHardDeleteCtx

func (t *Table) DoHardDeleteCtx(ctx context.Context, id interface{}) error

DoHardDelete deletes row completely.

func (*Table) DoHardDeleteTx

func (t *Table) DoHardDeleteTx(tx *Tx, id interface{}) error

func (*Table) DoHardDeleteTxCtx

func (t *Table) DoHardDeleteTxCtx(ctx context.Context, tx *Tx, id interface{}) error

func (*Table) DoInsert

func (t *Table) DoInsert(row interface{}, returning ...interface{}) error

func (*Table) DoInsertCtx

func (t *Table) DoInsertCtx(ctx context.Context, row interface{}, returning ...interface{}) error

func (*Table) DoInsertTx

func (t *Table) DoInsertTx(tx *Tx, row interface{}, returning ...interface{}) error

func (*Table) DoInsertTxCtx

func (t *Table) DoInsertTxCtx(ctx context.Context, tx *Tx, row interface{}, returning ...interface{}) error

func (*Table) DoSelect

func (t *Table) DoSelect(where, order string, offset, limit int, f func() error, row interface{}, params ...interface{}) error

func (*Table) DoSelectByID

func (t *Table) DoSelectByID(id interface{}, row interface{}) error

func (*Table) DoSelectCache

func (t *Table) DoSelectCache(f func() error, row interface{}) error

func (*Table) DoSelectCacheCtx

func (t *Table) DoSelectCacheCtx(ctx context.Context, f func() error, row interface{}) error

func (*Table) DoSelectCtx

func (t *Table) DoSelectCtx(ctx context.Context, where, order string, offset, limit int, f func() error, row interface{}, params ...interface{}) error

func (*Table) DoSelectCtxTx added in v0.1.1

func (t *Table) DoSelectCtxTx(tx *Tx, where, order string, offset, limit int, f func() error, row interface{}, params ...interface{}) error

func (*Table) DoSelectRow added in v0.5.0

func (t *Table) DoSelectRow(where string, row interface{}, args ...interface{}) error

func (*Table) DoSelectTx added in v0.1.1

func (t *Table) DoSelectTx(tx *Tx, where, order string, offset, limit int, f func() error, row interface{}, params ...interface{}) error

func (*Table) DoSoftDelete

func (t *Table) DoSoftDelete(id interface{}, deletedAt *NullTime, rowVersion *int) error

DoSoftDelete marks rows as deleted. Works only if table has column deleted_at, panics if not.

func (*Table) DoSoftDeleteCtx

func (t *Table) DoSoftDeleteCtx(ctx context.Context, id interface{}, deletedAt *NullTime, rowVersion *int) error

func (*Table) DoSoftDeleteTx

func (t *Table) DoSoftDeleteTx(tx *Tx, id interface{}, deletedAt *NullTime, rowVersion *int) error

func (*Table) DoSoftDeleteTxCtx

func (t *Table) DoSoftDeleteTxCtx(ctx context.Context, tx *Tx, id interface{}, deletedAt *NullTime, rowVersion *int) error

func (*Table) DoUpdate

func (t *Table) DoUpdate(row interface{}, tags string, rule TagExclusionRule, userID int) error

func (*Table) DoUpdateCtx

func (t *Table) DoUpdateCtx(ctx context.Context, row interface{}, tags string, rule TagExclusionRule, userID int) error

func (*Table) DoUpdateRowVersionCtx

func (t *Table) DoUpdateRowVersionCtx(ctx context.Context, id interface{}, updatedAt *NullTime, rowVersion *int) error

func (*Table) DoUpdateRowVersionTx

func (t *Table) DoUpdateRowVersionTx(tx *Tx, id interface{}, updatedAt *NullTime, rowVersion *int) error

func (*Table) DoUpdateRowVersionTxCtx

func (t *Table) DoUpdateRowVersionTxCtx(ctx context.Context, tx *Tx, id interface{}, updatedAt *NullTime, rowVersion *int) error

func (*Table) DoUpdateTx

func (t *Table) DoUpdateTx(tx *Tx, row interface{}, tags string, rule TagExclusionRule, userID int) error

func (*Table) DoUpdateTxCtx

func (t *Table) DoUpdateTxCtx(ctx context.Context, tx *Tx, row interface{}, tags string, rule TagExclusionRule, userID int) error

func (*Table) FieldAddrs

func (t *Table) FieldAddrs(model interface{}, tags string, rule TagExclusionRule) []interface{}

func (*Table) FieldAddrsSelect

func (t *Table) FieldAddrsSelect(model interface{}, tags string, rule TagExclusionRule) []interface{}

func (*Table) FieldAddrsUpdate

func (t *Table) FieldAddrsUpdate(model interface{}, tags string, rule TagExclusionRule) ([]interface{}, *NullTime, *int)

func (*Table) FieldNames

func (t *Table) FieldNames(model interface{}, tags string, rule TagExclusionRule) string

func (*Table) Insert added in v0.2.0

func (t *Table) Insert(row interface{}, optFunc ...func(*Option)) error

func (*Table) Name

func (t *Table) Name() string

func (*Table) SetAudit

func (t *Table) SetAudit(b bool)

SetAudit activates or diactivates audit mode for the table.

func (*Table) SetLogger

func (t *Table) SetLogger(l *zerolog.Logger)

func (*Table) SnakeIt

func (t *Table) SnakeIt(fieldName string) string

func (*Table) Update added in v0.2.3

func (t *Table) Update(row interface{}, optFunc ...func(*Option)) error

func (*Table) ValidateRow

func (t *Table) ValidateRow(row interface{}, mask int) RowValidationResult

ValidateRow

type TableDesc

type TableDesc struct {
	Ref **Table
	Row interface{}
}

type TagExclusionRule

type TagExclusionRule int

TagExclusionRule описывает тип исключения или включения атрибутов структур в SQL запрос.

const (
	Exclude TagExclusionRule = 1
	Include TagExclusionRule = 2
	All     TagExclusionRule = 3
)

func (TagExclusionRule) String

func (ter TagExclusionRule) String() string

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

Tx describes transaction.

func (*Tx) Commit

func (tx *Tx) Commit() *Tx

Commit commits transaction Tx.

func (*Tx) Duration

func (tx *Tx) Duration() time.Duration

Duration returns transaction duration. If transaction finished, returns transaction duration. If transaction is still open, returns duration from transaction start time.

func (*Tx) Err

func (tx *Tx) Err() error

Err returns error if transaction failed.

func (*Tx) ID

func (tx *Tx) ID() uint64

ID returns transaction ID. The number is usefull in logging, makes able to join many SQL statements under a single transaction number.

func (*Tx) Rollback

func (tx *Tx) Rollback() *Tx

Rollback rollbacks transaction.

func (*Tx) SQLTx

func (tx *Tx) SQLTx() *sql.Tx

SQLTx returns original *sql.Tx object.

Jump to

Keyboard shortcuts

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