templatedb

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// PoolID is the ID of the pool that this template database belongs to.
	PoolID string

	// ConnPool is the pgxpool.Pool to use for root database connections.
	ConnPool *pgxpool.Pool

	// Setup is the function that sets up the template database.
	Setup func(context.Context, *pgx.Conn) error

	// DatabaseOwner specifies the owner for the template and test databases.
	// If empty, uses the default owner (connection user).
	DatabaseOwner string
}

type TemplateDB

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

TemplateDB represents the template database.

func New

func New(cfg *Config) (*TemplateDB, error)

New creates a new TemplateDB instance with the given configuration.

func (*TemplateDB) Cleanup

func (t *TemplateDB) Cleanup(ctx context.Context) error

Cleanup drops the template database and releases any resources.

func (*TemplateDB) Create

func (t *TemplateDB) Create(ctx context.Context, name string) (*pgxpool.Pool, error)

Create creates a new database using the template database and returns a pgxpool.Pool connected to the new database.

func (*TemplateDB) Name

func (t *TemplateDB) Name() string

Name returns the name of the template database.

func (*TemplateDB) SanitizedName

func (t *TemplateDB) SanitizedName() string

SanitizedName returns the sanitized name of the template database. This is useful for safely using the name in SQL queries.

func (*TemplateDB) Setup

func (t *TemplateDB) Setup(ctx context.Context) error

Setup sets up the template database using the provided Setup function. This method is idempotent; it will only set up the database if it has not been set up yet.

Jump to

Keyboard shortcuts

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