testcontainer_formulas/postgres
Postgres formula. Defaults to postgres:16-alpine, database postgres,
user postgres, password postgres.
use pg <- testcontainer.with_formula(
postgres.new()
|> postgres.with_database("myapp_test")
|> postgres.with_password("secret")
|> postgres.formula(),
)
// pg.connection_url, pg.host, pg.port, pg.database, pg.username
Types
Postgres-specific configuration. Build with new/0 + with_*.
pub opaque type PostgresConfig
Typed output handed to the body of testcontainer.with_formula/2.
pub type PostgresContainer {
PostgresContainer(
container: container.Container,
connection_url: String,
host: String,
port: Int,
database: String,
username: String,
)
}
Constructors
-
PostgresContainer( container: container.Container, connection_url: String, host: String, port: Int, database: String, username: String, )
Values
pub fn formula(
c: PostgresConfig,
) -> formula.Formula(PostgresContainer)
Builds the Formula(PostgresContainer) ready to pass to
testcontainer.with_formula/2.
pub fn new() -> PostgresConfig
Sensible defaults: postgres:16-alpine / postgres / postgres / postgres.
pub fn on_network(
c: PostgresConfig,
net: network.Network,
) -> PostgresConfig
Attaches the container to the given network (typically built by
testcontainer.with_network/2 or testcontainer.with_stack/2).
pub fn on_network_name(
c: PostgresConfig,
net: String,
) -> PostgresConfig
Same as on_network/2 when you already have the Docker network name.
pub fn with_database(
c: PostgresConfig,
db: String,
) -> PostgresConfig
pub fn with_extra_wait(
c: PostgresConfig,
s: wait.WaitStrategy,
) -> PostgresConfig
Adds an extra wait strategy on top of the default
log("database system is ready to accept connections").
pub fn with_image(
c: PostgresConfig,
image: String,
) -> PostgresConfig
Replaces the image entirely (e.g. for hardened images or different bases).
pub fn with_name(c: PostgresConfig, n: String) -> PostgresConfig
Names the container so other containers on the same network can reach
it (e.g. "db" → db:5432).
pub fn with_password(
c: PostgresConfig,
pass: String,
) -> PostgresConfig
pub fn with_secret_password(
c: PostgresConfig,
pass: cowl.Secret(String),
) -> PostgresConfig
pub fn with_username(
c: PostgresConfig,
user: String,
) -> PostgresConfig
pub fn with_version(
c: PostgresConfig,
version: String,
) -> PostgresConfig
Shorthand: keep postgres: prefix, override only the tag.