dbwrapper

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: MIT Imports: 7 Imported by: 0

README

A simple, mockable wrapper for working with postgresql database in golang.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSlice = errors.New("GetList dest must be a slice")

ErrNotSlice is returned when dest passed to Query.GetList is not a slice.

View Source
var ErrToSQLFail = errors.New("can't convert to raw sql query")

ErrToSQLFail is returned when query builder fails to convert query to raw sql

Functions

func Connect added in v1.0.1

func Connect(ctx context.Context, url string) (*connectionPool, error)

Connect establishes a connection to the database and initializes a connection pool.

func SampleFunc

func SampleFunc() int

Types

type Query added in v1.0.1

type Query interface {
	// Get retrieves a single row.
	Get(ctx context.Context, qb Sqlizer, dest any) error
	// GetList retrieves multiple rows.
	GetList(ctx context.Context, qb Sqlizer, dest any) error
	// Exec executes a query.
	Exec(ctx context.Context, qb Sqlizer) error
	// BeginTx begins a transaction.
	BeginTx(ctx context.Context) (Tx, error)
}

Query defines interface for query runner.

type Sqlizer added in v1.0.1

type Sqlizer interface {
	ToSql() (sqlQuery string, args []any, err error)
}

Sqlizer defines interface for converter from a query builder to sql query with args.

type Tx

type Tx interface {
	Query
	// Rollback rolls back the transaction.
	Rollback(ctx context.Context) error
	// Commit commits the transaction.
	Commit(ctx context.Context) error
}

Tx defines interface for transaction runner.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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