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 cache_handler(
cmd: command.Command,
cache_db_handler: fn(
command.Args,
pool.Pool,
List(driver.CacheStore),
) -> Nil,
) -> command.Command
Sets a cache 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 and cache stores
- Stops the pool when done
Your handler receives a fully typed glimr_postgres.Pool and
the list of cache stores for configuration lookup.
pub fn handler(
cmd: command.Command,
db_handler: fn(command.Args, 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.