database

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorEmptySqlResult     string = "ERROR_EMPTY_SQL_RESULT"
	ErrorDatabaseDuplicated string = "ERROR_DUPLICATED_ENTRY"
)
View Source
const ErrorNoRowsAffected string = "ERROR_SQL_NO_ROWS_AFFECTED"

Variables

This section is empty.

Functions

func GetSqlError

func GetSqlError(err error) error

func ManageUpdateError

func ManageUpdateError(callerName string, result sql.Result, err error) error

Manages the possible error coming for an update execution and returns the database error if exists. If not, it checks if any row has been affected and returns err if nothing has been updated.

  params

	'callerName' is the name of the caller function, it is used in log message
	'result' is the sql.Result returned by Exec function
	'err' is the error returned by Exec function

Types

type DbConnection

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

func CreateConnection

func CreateConnection(user, password, databaseName, host string, port, timeout uint16) (*DbConnection, error)

CreateConnection creates the DB connection. time out must be in seconds

func (*DbConnection) BeginEnhacedTx

func (d *DbConnection) BeginEnhacedTx() (*EnhacedTx, error)

Returns a new Enhaced Improved Transaction

func (*DbConnection) BeginTx

func (d *DbConnection) BeginTx() (*sql.Tx, error)

Returns a new Transaction

func (*DbConnection) Close

func (d *DbConnection) Close()

Close closes de DB connection

func (*DbConnection) GetConnection

func (d *DbConnection) GetConnection() *sql.DB

Gets the DB connection

type EnhacedTx

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

func (*EnhacedTx) Commit

func (v *EnhacedTx) Commit() error

Commit commits the transaction

func (*EnhacedTx) Exec

func (v *EnhacedTx) Exec(query string, args ...any) (sql.Result, error)

Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.

func (*EnhacedTx) ForceClose

func (v *EnhacedTx) ForceClose() error

ForceClose closes and aborts the transaction

func (*EnhacedTx) IsActive

func (v *EnhacedTx) IsActive() bool

IsOpen returns true if the transaction is still active

func (*EnhacedTx) Query

func (v *EnhacedTx) Query(query string, args ...any) (*sql.Rows, error)

Query executes a query that returns rows, typically a SELECT.

func (*EnhacedTx) QueryRow

func (v *EnhacedTx) QueryRow(query string, args ...any) *sql.Row

QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until [Row]'s Scan method is called.

func (*EnhacedTx) Rollback

func (v *EnhacedTx) Rollback() error

Rollback aborts the transaction

Jump to

Keyboard shortcuts

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