#env-var #postgresql #service-configuration #sql #client-config #string-parser

bin+lib pg-client-config

Support for Postgres service configuration files and environment variables

3 releases

0.1.2 Aug 26, 2023
0.1.1 Apr 14, 2023
0.1.0 Apr 6, 2023

#1126 in Database interfaces

Download history 109/week @ 2024-07-26 139/week @ 2024-08-02 95/week @ 2024-08-09 63/week @ 2024-08-16 111/week @ 2024-08-23 104/week @ 2024-08-30 107/week @ 2024-09-06 117/week @ 2024-09-13 276/week @ 2024-09-20 186/week @ 2024-09-27 152/week @ 2024-10-04 187/week @ 2024-10-11 160/week @ 2024-10-18 224/week @ 2024-10-25 84/week @ 2024-11-01 79/week @ 2024-11-08

576 downloads per month

MIT/Apache

22KB
407 lines

Tokio-postgres support for service file and environment variables.

Connection string parsing with support for service file and a subset of psql environment variables.

Note: tokio-postgres 0.7.9 introduced a change preventing PGUSER and service configuration to set connection user. The release of tokio-postgres 0.7.10 fix this issue.

Environment variables

  • PGSERVICE - Name of the postgres service used for connection params.
  • PGSYSCONFDIR - Location of the service files.
  • PGSERVICEFILE - Name of the service file.
  • PGHOST - behaves the same as the host connection parameter.
  • PGPORT - behaves the same as the port connection parameter.
  • PGDATABASE - behaves the same as the dbname connection parameter.
  • PGUSER - behaves the same as the user connection parameter.
  • PGOPTIONS - behaves the same as the options parameter.
  • PGAPPNAME - behaves the same as the application_name connection parameter.
  • PGCONNECT_TIMEOUT - behaves the same as the connect_timeout connection parameter.
  • PGPASSFILE - Specifies the name of the file used to store password.

Passfile support

Passfile is actually supported only on linux platform

Example

use pg_client_config::load_config;

let config = load_config(Some("service=myservice")).unwrap();
println!("{config:#?}");

Precedence rules

  • Environment variables are always evaluated with the least precedence.
  • Parameters passed in the connection string always take precedence.

See also

Dependencies

~8–17MB
~241K SLoC