Documentation
¶
Index ¶
- type Config
- type EmbeddedPostgres
- func (pg *EmbeddedPostgres) ConnectionString(dbName string) (string, error)
- func (pg *EmbeddedPostgres) CreateDatabase(dbName string, owner string) error
- func (pg *EmbeddedPostgres) DatabaseExists(dbName string) (bool, error)
- func (pg *EmbeddedPostgres) DropDatabase(dbName string) error
- func (pg *EmbeddedPostgres) Stop() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Version of PostgreSQL to use (e.g., "16.2.0", "15.6.0", "14.11.0", etc.). Mandatory.
// Check postgresql-embedded crate for supported versions.
Version string
// DataDir is the path to the PostgreSQL data directory.
// If empty, a temporary directory managed by the Rust library will be used.
DataDir string
// RuntimeDir is the path for runtime files (e.g., sockets).
// If empty, a temporary directory managed by the Rust library will be used.
RuntimeDir string
// Port for PostgreSQL to listen on. If 0, a random available port will be chosen.
Port uint16
// Password for the default 'postgres' user. If empty, password may not be set or a default used.
Password string
}
Config holds configuration for the embedded PostgreSQL.
type EmbeddedPostgres ¶
type EmbeddedPostgres struct {
// contains filtered or unexported fields
}
EmbeddedPostgres represents an embedded PostgreSQL instance.
func New ¶
func New(config Config) (*EmbeddedPostgres, error)
New initializes, downloads (if necessary), and starts an embedded PostgreSQL instance. The first run for a specific PostgreSQL version might take time to download binaries. Binaries are cached by `postgresql-embedded` typically in `~/.embed-postgres/`.
func (*EmbeddedPostgres) ConnectionString ¶
func (pg *EmbeddedPostgres) ConnectionString(dbName string) (string, error)
ConnectionString returns a libpq-compatible connection string for the given database name. If dbName is empty, "postgres" is typically used as the default database.
func (*EmbeddedPostgres) CreateDatabase ¶
func (pg *EmbeddedPostgres) CreateDatabase(dbName string, owner string) error
CreateDatabase creates a new database in the embedded instance. The default owner is 'postgres' if owner string is empty.
func (*EmbeddedPostgres) DatabaseExists ¶
func (pg *EmbeddedPostgres) DatabaseExists(dbName string) (bool, error)
DatabaseExists checks if a database with the given name exists.
func (*EmbeddedPostgres) DropDatabase ¶
func (pg *EmbeddedPostgres) DropDatabase(dbName string) error
DropDatabase drops an existing database from the embedded instance.
func (*EmbeddedPostgres) Stop ¶
func (pg *EmbeddedPostgres) Stop() error
Stop shuts down and cleans up the embedded PostgreSQL instance. It's safe to call Stop multiple times. This method is also registered as a finalizer for the EmbeddedPostgres struct.