PgORM::Settings
Inherits Habitat::SettingsHelpers < Habitat::TempConfig
Database connection settings and configuration.
Settings can be configured via environment variables or programmatically. The module uses the Habitat shard for configuration management.
Environment Variables
PG_HOST: Database host (default: "localhost")PG_PORT: Database port (default: 5432)PG_DBorPG_DATABASE: Database name (default: "test")PG_USER: Database user (default: "postgres")PG_PASSWORD: Database password (default: "")PG_QUERY: Additional query parameters (default: "")PG_LOCK_TIMEOUT: Advisory lock timeout in seconds (default: 5)
Programmatic Configuration
# Configure individual settings
PgORM::Database.configure do |settings|
settings.host = "db.example.com"
settings.port = 5432
settings.db = "production"
settings.user = "app_user"
settings.password = "secret"
end
# Or parse a connection URL
PgORM::Database.parse("postgres://user:pass@localhost:5432/mydb")
Constants
Class methods
Parses a PostgreSQL connection URI and updates settings.
This is useful for configuring the database from a single connection string, such as from environment variables in production.
Example
# From string
PgORM::Settings.parse("postgres://user:pass@localhost:5432/mydb")
# From environment variable
PgORM::Settings.parse(ENV["DATABASE_URL"])
# From URI object
uri = URI.parse("postgres://user:pass@localhost:5432/mydb")
PgORM::Settings.parse(uri)
Configures the read-only replica connection from a URL. Pass nil to
disable replica routing and send all reads to the primary.
Example
PgORM::Settings.parse_read(ENV["PG_DATABASE_READ_URL"]?)
The configured read-only replica connection URL, or nil when no replica
is configured (in which case reads use the primary connection).
Builds a PostgreSQL connection URI from the current settings.
The URI is cached after first generation for performance.
Example
PgORM::Settings.to_uri
# => "postgres://user:pass@localhost:5432/mydb"