pub struct AfdCli { /* private fields */ }Expand description
afpsql gives agents a reliable PostgreSQL contract: structured stdout
events, first-class SSH/container transports, explicit write permissions,
stable pipe sessions, and machine-readable failures.
§Interface Policy
- default mode is canonical agent-first CLI
--mode psqlis argument translation only; runtime output stays JSONL- stdout carries protocol events; stderr is not a protocol channel
- native CLI and pipe mode default to read-only transactions; writes require permission
- SSH/container transports keep afpsql local instead of running human
psqlacross boundaries
§Modes
- default (native CLI): one SQL action per process — a single agent step
--mode pipe: a long-lived JSONL session withidcorrelation and named sessions for multi-step work--mode psql: run existingpsqlscripts unchanged — flags are translated, runtime output stays JSONL
§Query Sources and Parameters
- use
--sqlfor inline SQL or--sql-filefor a file - use repeatable
--param N=valuefor positional binds - placeholder count is validated from prepared-statement metadata, not by SQL text scanning
§Connection Sources
--dsn-secretfor a PostgreSQL URI--conninfo-secretfor libpq-style conninfo- or discrete
--host,--port,--user,--dbname,--password-secret - every
*-secretflag has a*-secret-envpartner that reads the value from a named environment variable - every secret slot also has a
*-secret-config FILE DOT_PATHsource for JSON, TOML, YAML, or dotenv - add
--ssh user@serverwhen PostgreSQL is reachable only from the server boundary - add
--container TARGETwhen PostgreSQL is reachable only from inside a container boundary - use named container scope flags instead of raw driver option passthrough
- use
--container-driver docker|podman|nerdctl|compose|kubectlfor the exec syntax - combine
--ssh user@server --container TARGETfor containers on an SSH host - agent-first environment fallbacks:
AFPSQL_* - PostgreSQL environment fallbacks:
PGHOST,PGPORT,PGUSER,PGDATABASE,PGPASSWORD,PGSSLMODE
§Result Shaping
- default mode buffers a bounded inline result
- use
--stream-rowsfor large result sets, with--batch-rowsand--batch-bytesto tune chunk size --output json|yaml|plainchanges rendering only, not the runtime schema
§Examples
afpsql --sql "select now() as now_rfc3339"
afpsql --sql-file ./query.sql
afpsql --sql 'select * from users where id = $1' --param 1=123
afpsql --dsn-secret-env DATABASE_URL --sql "select 1"
afpsql --dsn-secret-config config.yaml database.url --sql "select 1"
afpsql --ssh user@server --host 127.0.0.1 --port 5432 --user app --dbname appdb --sql "select 1"
afpsql --container pg-container --dsn-secret-env DATABASE_URL --sql "select 1"
afpsql --ssh root@server --container app --host host.container.internal --port 5432 --user app --dbname appdb --sql "select 1"
afpsql --mode psql -h 127.0.0.1 -p 5432 -U app -d appdb -c "select 1"
afpsql --sql "select * from big_table" --stream-rows --batch-rows 1000
afpsql --mode pipe
afpsql psql status
afpsql psql install
afpsql skill status
afpsql skill install§Exit Codes
0: query completed successfully1: SQL error or runtime error2: invalid CLI arguments
Trait Implementations§
Source§impl Args for AfdCli
impl Args for AfdCli
Source§fn augment_args<'b>(__clap_app: Command) -> Command
fn augment_args<'b>(__clap_app: Command) -> Command
Source§fn augment_args_for_update<'b>(__clap_app: Command) -> Command
fn augment_args_for_update<'b>(__clap_app: Command) -> Command
Append to
Command so it can instantiate self via
FromArgMatches::update_from_arg_matches_mut Read moreSource§impl CommandFactory for AfdCli
impl CommandFactory for AfdCli
Source§impl FromArgMatches for AfdCli
impl FromArgMatches for AfdCli
Source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
Source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches,
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>
Source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>
Assign values from
ArgMatches to self.Source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>
Assign values from
ArgMatches to self.Source§impl Parser for AfdCli
impl Parser for AfdCli
Source§fn parse_from<I, T>(itr: I) -> Self
fn parse_from<I, T>(itr: I) -> Self
Parse from iterator, exit on error.
Source§fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
Parse from iterator, return Err on error.
Source§fn update_from<I, T>(&mut self, itr: I)
fn update_from<I, T>(&mut self, itr: I)
Auto Trait Implementations§
impl Freeze for AfdCli
impl RefUnwindSafe for AfdCli
impl Send for AfdCli
impl Sync for AfdCli
impl Unpin for AfdCli
impl UnsafeUnpin for AfdCli
impl UnwindSafe for AfdCli
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more