glimr_postgres/console/command
PostgreSQL Command Support
Provides helpers for creating console commands that need PostgreSQL database access. The handler function wraps your command logic with automatic pool management.
Example
import glimr/console/command
import glimr_postgres/command as postgres_command
pub fn my_command() -> command.Command {
command.new()
|> command.name("my:command")
|> command.description("Does database stuff")
|> postgres_command.handler(fn(args, pool) {
// pool is glimr_postgres.Pool - fully typed!
use conn <- glimr_postgres.with_connection(pool)
// ...
})
}
Values
pub fn handler(
cmd: command.Command,
db_handler: fn(command.ParsedArgs, pool.Pool) -> Nil,
) -> command.Command
Sets a database handler for a command. Automatically:
- Adds the –database option
- Validates the connection exists and is PostgreSQL
- Starts a typed pool
- Calls your handler with the pool
- Stops the pool when done
Your handler receives a fully typed glimr_postgres.Pool.