dbrepo

package
v0.0.0-...-7c5da1f Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRowsUpdated = errors.New("error on Update, no affected rows")
View Source
var TxKey = TxKeyType("tx")

Functions

func AddTxToContext

func AddTxToContext(ctx context.Context, tx *sql.Tx) context.Context

func ConnectoToTestDB

func ConnectoToTestDB() *sql.DB

func Test

func Test(cb func(ctx context.Context, db *sql.DB))

Test connects to the database, starts a transaction and puts it in the context passing it to the given callback. This context is supposed to be used by all the repositories in the test. After the callback is run, the transaction is rolled back returning the database to the initial state.

func TxFromContext

func TxFromContext(ctx context.Context) *sql.Tx

Types

type Base

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

func NewBase

func NewBase(db *sql.DB) *Base

func (*Base) Conn

func (r *Base) Conn(ctx context.Context) Connection

func (*Base) Exec

func (r *Base) Exec(ctx context.Context, query string, args ...interface{}) (int64, error)

func (*Base) Insert

func (r *Base) Insert(
	ctx context.Context, tableName string, values map[string]interface{},
) error

func (*Base) Update

func (r *Base) Update(
	ctx context.Context, tableName string, id string, values map[string]interface{},
) error

type Connection

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

type TxKeyType

type TxKeyType string

Jump to

Keyboard shortcuts

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