Documentation ¶
Index ¶
- Constants
- func TestGetConnectionURL(t *testing.T)
- type CacheLocator
- type Config
- func (c Config) BinariesPath(path string) Config
- func (c Config) BinaryRepositoryURL(binaryRepositoryURL string) Config
- func (c Config) CachePath(path string) Config
- func (c Config) DataPath(path string) Config
- func (c Config) Database(database string) Config
- func (c Config) GetConnectionURL() string
- func (c Config) Locale(locale string) Config
- func (c Config) Logger(logger io.Writer) Config
- func (c Config) Password(password string) Config
- func (c Config) Port(port uint32) Config
- func (c Config) RunAsUser(runAsUser string) Config
- func (c Config) RuntimePath(path string) Config
- func (c Config) StartParameters(parameters map[string]string) Config
- func (c Config) StartTimeout(timeout time.Duration) Config
- func (c Config) Username(username string) Config
- func (c Config) Version(version PostgresVersion) Config
- type EmbeddedPostgres
- type PostgresVersion
- type RemoteFetchStrategy
- type VersionStrategy
Constants ¶
const ( V16 = PostgresVersion("16.2.0") V15 = PostgresVersion("15.6.0") V14 = PostgresVersion("14.11.0") V13 = PostgresVersion("13.14.0") V12 = PostgresVersion("12.17.0") V11 = PostgresVersion("11.22.0") V10 = PostgresVersion("10.23.0") V9 = PostgresVersion("9.6.24") )
Predefined supported Postgres versions.
Variables ¶
This section is empty.
Functions ¶
func TestGetConnectionURL ¶
Types ¶
type CacheLocator ¶
CacheLocator retrieves the location of the Postgres binary cache returning it to location. The result of whether this cache is present will be returned to exists.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config maintains the runtime configuration for the Postgres process to be created.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig provides a default set of configuration to be used "as is" or modified using the provided builders. The following can be assumed as defaults: Version: 15 Port: 5432 Database: postgres Username: postgres Password: postgres StartTimeout: 15 Seconds
func (Config) BinariesPath ¶
BinariesPath sets the path of the pre-downloaded postgres binaries. If this option is left unset, the binaries will be downloaded.
func (Config) BinaryRepositoryURL ¶
BinaryRepositoryURL set BinaryRepositoryURL to fetch PG Binary in case of Maven proxy
func (Config) CachePath ¶
CachePath sets the path that will be used for storing Postgres binaries archive. If this option is not set, ~/.go-embedded-postgres will be used.
func (Config) DataPath ¶
DataPath sets the path that will be used for the Postgres data directory. If this option is set, a previously initialized data directory will be reused if possible.
func (Config) GetConnectionURL ¶
func (Config) RuntimePath ¶
RuntimePath sets the path that will be used for the extracted Postgres runtime directory. If Postgres data directory is not set with DataPath(), this directory is also used as data directory.
func (Config) StartParameters ¶
StartParameters sets run-time parameters when starting Postgres (passed to Postgres via "-c").
These parameters can be used to override the default configuration values in postgres.conf such as max_connections=100. See https://www.postgresql.org/docs/current/runtime-config.html
func (Config) StartTimeout ¶
StartTimeout sets the max timeout that will be used when starting the Postgres process and creating the initial database.
func (Config) Version ¶
func (c Config) Version(version PostgresVersion) Config
Version will set the Postgres binary version.
type EmbeddedPostgres ¶
type EmbeddedPostgres struct {
// contains filtered or unexported fields
}
EmbeddedPostgres maintains all configuration and runtime functions for maintaining the lifecycle of one Postgres process.
func NewDatabase ¶
func NewDatabase(config ...Config) *EmbeddedPostgres
NewDatabase creates a new EmbeddedPostgres struct that can be used to start and stop a Postgres process. When called with no parameters it will assume a default configuration state provided by the DefaultConfig method. When called with parameters the first Config parameter will be used for configuration.
func (*EmbeddedPostgres) Start ¶
func (ep *EmbeddedPostgres) Start() error
Start will try to start the configured Postgres process returning an error when there were any problems with invocation. If any error occurs Start will try to also Stop the Postgres process in order to not leave any sub-process running.
func (*EmbeddedPostgres) Stop ¶
func (ep *EmbeddedPostgres) Stop() error
Stop will try to stop the Postgres process gracefully returning an error when there were any problems.
type PostgresVersion ¶
type PostgresVersion string
PostgresVersion represents the semantic version used to fetch and run the Postgres process.
type RemoteFetchStrategy ¶
type RemoteFetchStrategy func() error
RemoteFetchStrategy provides a strategy to fetch a Postgres binary so that it is available for use.
type VersionStrategy ¶
type VersionStrategy func() (operatingSystem string, architecture string, postgresVersion PostgresVersion)
VersionStrategy provides a strategy that can be used to determine which version of Postgres should be used based on the operating system, architecture and desired Postgres version.