pgtest

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0, MIT Imports: 13 Imported by: 0

README

Documentation

Overview

Spawns a PostgreSQL server with a single database configured. Ideal for unit tests where you want a clean instance each time. Then clean up afterwards.

Requires PostgreSQL to be installed on your system (but it doesn't have to be running).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PG

type PG struct {
	DB *pgxpool.Pool
	// contains filtered or unexported fields
}

func Start

func Start() (*PG, error)

Start a new PostgreSQL database, on temporary storage.

This database has fsync disabled for performance, so it might run faster than your production database. This makes it less reliable in case of system crashes, but we don't care about that anyway during unit testing.

Use the DB field to access the database connection.

func StartPersistent

func StartPersistent(folder string) (*PG, error)

Starts a new PostgreSQL database

Will listen on a unix socket and initialize the database in the given folder, if needed. Data isn't removed when calling Stop(), so this database can be used multiple times. Allows using PostgreSQL as an embedded databases (such as SQLite). Not for production usage!

func (*PG) Stop

func (p *PG) Stop()

Stop the database and remove storage files.

type PGConfig

type PGConfig struct {
	BinDir       string // Directory to look for postgresql binaries including initdb, postgres
	Dir          string // Directory for storing database files, removed for non-persistent configs
	IsPersistent bool   // Whether to make the current configuraton persistent or not
}

func New

func New() *PGConfig

func (*PGConfig) DataDir

func (c *PGConfig) DataDir(dir string) *PGConfig

func (*PGConfig) From

func (c *PGConfig) From(dir string) *PGConfig

func (*PGConfig) Persistent

func (c *PGConfig) Persistent() *PGConfig

func (*PGConfig) Start

func (c *PGConfig) Start() (*PG, error)

func (*PGConfig) UseBinariesIn

func (c *PGConfig) UseBinariesIn(dir string) *PGConfig

Jump to

Keyboard shortcuts

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