db

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestConninfo string

TestConninfo defines connection string to the test database. It is populated at test time by internal/dbtest.RunMain (from each package's TestMain) and points to a throwaway PostgreSQL container.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	Begin(ctx context.Context) (Tx, error)
	Exec(ctx context.Context, sql string, arguments ...interface{}) (int64, string, error)
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
	Close() error
}

func Connect

func Connect(ctx context.Context, connString string) (Conn, error)

Connect accepts connection string and create new connection.

type DB

type DB interface {
	Begin(ctx context.Context) (Tx, error)
	Exec(ctx context.Context, sql string, arguments ...interface{}) (int64, string, error)
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
	Close()
}

func NewPostgresDB

func NewPostgresDB(ctx context.Context, conninfo string) (DB, error)

NewPostgresDB creates new database connections pool.

func NewTestDB

func NewTestDB() (DB, error)

NewTestDB creates connection for test database.

type PostgresConn

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

PostgresConn wraps *pgx.Conn.

func (*PostgresConn) Begin

func (c *PostgresConn) Begin(ctx context.Context) (Tx, error)

Begin opens transaction in database and returns transaction object.

func (*PostgresConn) Close

func (c *PostgresConn) Close() error

func (*PostgresConn) Exec

func (c *PostgresConn) Exec(ctx context.Context, sql string, args ...interface{}) (int64, string, error)

Exec executes query expression and returns number of affected rows and resulting tag.

func (*PostgresConn) Query

func (c *PostgresConn) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

Query executes query expression and returns resulting Rows.

type PostgresDB

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

PostgresDB implements pgxpool.Pool as DB interface.

func (*PostgresDB) Begin

func (db *PostgresDB) Begin(ctx context.Context) (Tx, error)

Begin opens transaction in database and returns transaction object.

func (*PostgresDB) Close

func (db *PostgresDB) Close()

Close closes database connections pool.

func (*PostgresDB) Exec

func (db *PostgresDB) Exec(ctx context.Context, sql string, args ...interface{}) (int64, string, error)

Exec executes query expression and returns resulting tag.

func (*PostgresDB) Query

func (db *PostgresDB) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

Query executes query expression and returns resulting Rows.

type PostgresTx

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

PostgresTx implements PostgreSQL transaction object.

func (*PostgresTx) Commit

func (tx *PostgresTx) Commit(ctx context.Context) error

Commit does transaction commit.

func (*PostgresTx) Exec

func (tx *PostgresTx) Exec(ctx context.Context, sql string, args ...interface{}) (int64, string, error)

Exec executes query expression inside the transaction and returns resulting tag.

func (*PostgresTx) Query

func (tx *PostgresTx) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

Query executes query expression inside the transaction and returns resulting Rows.

func (*PostgresTx) Rollback

func (tx *PostgresTx) Rollback(ctx context.Context) error

Rollback does transaction rollback.

type Tx

type Tx interface {
	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error
	Exec(ctx context.Context, sql string, arguments ...interface{}) (int64, string, error)
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
}

Jump to

Keyboard shortcuts

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