### Start Database Pool in OTP Supervisor Source: https://github.com/lpil/pog/blob/main/README.md Configure and start a Pog database connection pool as a child process in an OTP supervision tree. Ensure the pool is started before any processes that will use it. ```gleam import gleam/otp/static_supervisor as supervisor import gleam/erlang/process import pog pub fn start_application_supervisor(pool_name: process.Name(pog.Message)) { let pool_child = pog.default_config(pool_name) |> pog.host("localhost") |> pog.database("my_database") |> pog.pool_size(15) |> pog.supervised supervisor.new(supervisor.RestForOne) |> supervisor.add(pool_child) // |> supervisor.add(other) // |> supervisor.add(application) // |> supervisor.add(children) |> supervisor.start } ``` -------------------------------- ### Dockerfile for Adding CA Certificates Source: https://github.com/lpil/pog/blob/main/docs/solving-ssl-issues.md This Dockerfile example demonstrates how to update package managers, install CA certificates, and add custom certificates (like AWS RDS certificates) to the system's trusted certificate store. This is useful for Alpine-based images or when dealing with self-signed CAs. ```dockerfile # Update your package manager. RUN apt update # Add the main CA certificates. RUN apt install -y ca-certificates inotify-tools curl # Get the latest CA certificates. RUN update-ca-certificates # Get the certificate form AWS. RUN mkdir -p /aws-certificates RUN curl -o /aws-certificates/rds.pem https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem # Provide the CA certificate in the OS directly. RUN cat /aws-certificates/rds.pem >> /etc/ssl/certs/ca-certificates.crt ``` -------------------------------- ### Execute a Query with Parameters and Decode Results Source: https://github.com/lpil/pog/blob/main/README.md Execute a SQL query with parameters and decode the returned rows into a specific Gleam structure. This example demonstrates fetching cat data by ID and asserting the results. ```gleam import pog import gleam/dynamic/decode pub fn run(db: pog.Connection) { // An SQL statement to run. It takes one int as a parameter let sql_query = " select name, age, colour, friends from cats where id = $1" // This is the decoder for the value returned by the query let row_decoder = { use name <- decode.field(0, decode.string) use age <- decode.field(1, decode.int) use colour <- decode.field(2, decode.string) use friends <- decode.field(3, decode.list(decode.string)) decode.success(#(name, age, colour, friends)) } // Run the query against the PostgreSQL database // The int `1` is given as a parameter let assert Ok(data) = pog.query(sql_query) |> pog.parameter(pog.int(1)) |> pog.returning(row_decoder) |> pog.execute(db) // And then do something with the returned results assert data.count == 2 assert data.rows == [#("Nubi", 3, "black", ["Al", "Cutlass"])] } ``` -------------------------------- ### PEM Certificate Structure Example Source: https://github.com/lpil/pog/blob/main/docs/solving-ssl-issues.md This is an example of the structure of a PEM certificate, commonly used for SSL/TLS communication. It includes the BEGIN and END markers and the base64 encoded certificate data. ```text -----BEGIN CERTIFICATE----- MIIEBjCCAu6gAwIBAgIJAMc0ZzaSUK51MA0GCSqGSIb3DQEBCwUAMIGPMQswCQYD VQQGEwJVUzEQMA4GA1UEBwwHU2VhdHRsZTETMBEGA1UECAwKV2FzaGluZ3RvbjEi MCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNlcywgSW5jLjETMBEGA1UECwwKQW1h em9uIFJEUzEgMB4GA1UEAwwXQW1hem9uIFJEUyBSb290IDIwMTkgQ0EwHhcNMTkw ODIyMTcwODUwWhcNMjQwODIyMTcwODUwWjCBjzELMAkGA1UEBhMCVVMxEDAOBgNV BAcMB1NlYXR0bGUxEzARBgNVBAgMCldhc2hpbmd0b24xIjAgBgNVBAoMGUFtYXpv biBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMxIDAeBgNV BAMMF0FtYXpvbiBSRFMgUm9vdCAyMDE5IENBMIIBIjANBgkqhkiG9w0BAQEFAAOC AQ8AMIIBCgKCAQEArXnF/E6/Qh+ku3hQTSKPMhQQlCpoWvnIthzX6MK3p5a0eXKZ oWIjYcNNG6UwJjp4fUXl6glp53Jobn+tWNX88dNH2n8DVbppSwScVE2LpuL+94vY 0EYE/XxN7svKea8YvlrqkUBKyxLxTjh+U/KrGOaHxz9v0l6ZNlDbuaZw3qIWdD/I 6aNbGeRUVtpM6P+bWIoxVl/caQylQS6CEYUk+CpVyJSkopwJlzXT07tMoDL5WgX9 O08KVgDNz9qP/IGtAcRduRcNioH3E9v981QO1zt/Gpb2f8NqAjUUCUZzOnij6mx9 McZ+9cWX88CRzR0vQODWuZscgI08NvM69Fn2SQIDAQABo2MwYTAOBgNVHQ8BAf8E BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUc19g2LzLA5j0Kxc0LjZa pmD/vB8wHwYDVR0jBBgwFoAUc19g2LzLA5j0Kxc0LjZapmD/vB8wDQYJKoZIhvcN AQELBQADggEBAHAG7WTmyjzPRIM85rVj+fWHsLIvqpw6DObIjMWokpliCeMINZFV ynfgBKsf1ExwbvJNzYFXW6dihnguDG9VMPpi2up/ctQTN8tm9nDKOy08uNZoofMc NUZxKCEkVKZv+IL4oHoeayt8egtv3ujJM6V14AstMQ6SwvwvA93EP/Ug2e4WAXHu cbI1NAbUgVDqp+DRdfvZkgYKryjTWd/0+1fS8X1bBZVWzl7eirNVnHbSH2ZDpNuY 0SBd8dj5F6ld3t58ydZbrTHze7JJOd8ijySAp4/kiu9UfZWuTPABzDa/DSdz9Dk/ zPW4CXXvhLmE02TA9/HeCw3KEHIwicNuEfw= -----END CERTIFICATE----- ``` -------------------------------- ### Set Postgres Environment Variables Source: https://github.com/lpil/pog/blob/main/test/README.md Configure these environment variables before running tests to connect to the Postgres database. ```sh export PGUSER="postgres" export PGHOST="localhost" export PGPASSWORD="postgres" export PGUSER="postgres" export PGPORT=5432 ``` -------------------------------- ### Read Connection URI from Environment Source: https://github.com/lpil/pog/blob/main/README.md Configure a Pog database connection using a connection URI string read from the DATABASE_URL environment variable. This function returns a Result, handling potential errors during environment variable retrieval or URI parsing. ```gleam import envoy import gleam/erlang/process.{type Name} import pog /// Read the DATABASE_URL environment variable and then /// build the pog.Config from that database URL. pub fn read_connection_uri(name: Name(pog.Message)) -> Result(pog.Config, Nil) { use database_url <- result.try(envoy.get("DATABASE_URL")) pog.url_config(name, database_url) } ``` -------------------------------- ### Add Pog Dependency Source: https://github.com/lpil/pog/blob/main/README.md Add the Pog package to your Gleam project using the Gleam package manager. ```gleam gleam add pog@4 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.