pg

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 18 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestDB

func NewTestDB(t testing.TB, dbURL string) *sqlx.DB

func RegisterTxDb

func RegisterTxDb(dbURL string) error

txdb is a simplified version of https://github.com/DATA-DOG/go-txdb

The original lib has various problems and is hard to understand because it tries to be more general. The version in this file is more tightly focused to our needs and should be easier to reason about and less likely to have subtle bugs/races.

It doesn't currently support savepoints but could be made to if necessary.

Transaction BEGIN/ROLLBACK effectively becomes a no-op, this should have no negative impact on normal test operation.

If you MUST test BEGIN/ROLLBACK behaviour, you will have to configure your store to use the raw DialectPostgres dialect and setup a one-use database. See heavyweight.FullTestDB() as a convenience function to help you do this, but please use sparingly because as it's name implies, it is expensive.

func TestURL

func TestURL(t testing.TB) string

Types

type DialectName

type DialectName string

DialectName is a compiler enforced type used that maps to database dialect names

const (
	// Postgres represents the postgres dialect.
	Postgres DialectName = "pgx"
	// TransactionWrappedPostgres is useful for tests.
	// When the connection is opened, it starts a transaction and all
	// operations performed on the DB will be within that transaction.
	TransactionWrappedPostgres DialectName = "txdb"
	InMemoryPostgres           DialectName = "duckdb"
)

Jump to

Keyboard shortcuts

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