Expand description
Connection string parsing and multi-database configuration.
This module provides utilities for parsing database connection URLs and managing configurations for multiple database backends.
§Supported URL Formats
§PostgreSQL
postgres://user:password@host:port/database?options
postgresql://user:password@host:port/database?options§MySQL
mysql://user:password@host:port/database?options
mariadb://user:password@host:port/database?options§SQLite
sqlite://path/to/database.db?options
sqlite::memory:
file:path/to/database.db?options§Parsing Connection URLs
use prax_query::ConnectionString;
// PostgreSQL URL
let conn = ConnectionString::parse("postgres://user:pass@localhost:5432/mydb").unwrap();
assert_eq!(conn.host(), Some("localhost"));
assert_eq!(conn.port(), Some(5432));
assert_eq!(conn.database(), Some("mydb"));
// MySQL URL
let conn = ConnectionString::parse("mysql://user:pass@localhost:3306/mydb").unwrap();
// SQLite URL (note: uses :// prefix)
let conn = ConnectionString::parse("sqlite://./data.db").unwrap();§Driver Types
use prax_query::Driver;
// Default ports
assert_eq!(Driver::Postgres.default_port(), Some(5432));
assert_eq!(Driver::MySql.default_port(), Some(3306));
assert_eq!(Driver::Sqlite.default_port(), None);
// Parse from scheme
assert_eq!(Driver::from_scheme("postgres").unwrap(), Driver::Postgres);
assert_eq!(Driver::from_scheme("postgresql").unwrap(), Driver::Postgres);
assert_eq!(Driver::from_scheme("mysql").unwrap(), Driver::MySql);
assert_eq!(Driver::from_scheme("mariadb").unwrap(), Driver::MySql);
assert_eq!(Driver::from_scheme("sqlite").unwrap(), Driver::Sqlite);§SSL Modes
use prax_query::connection::SslMode;
// Available SSL modes
let mode = SslMode::Disable; // No SSL
let mode = SslMode::Prefer; // Use SSL if available
let mode = SslMode::Require; // Require SSL
let mode = SslMode::VerifyCa; // Verify CA certificate
let mode = SslMode::VerifyFull; // Verify CA and hostnameStructs§
- Connection
Options - Common connection options.
- Connection
String - Connection string parser.
- Database
Config - Complete database configuration.
- Database
Config Builder - Builder for database configuration.
- EnvExpander
- Expands environment variables in strings.
- Multi
Database Config - Configuration for multiple databases.
- MySql
Options - MySQL-specific options.
- Parsed
Url - A parsed database URL.
- Pool
Config - Complete pool configuration combining connection and pool options.
- Pool
Options - Pool options.
- Postgres
Options - PostgreSQL-specific options.
- Sqlite
Options - SQLite-specific options.
- SslConfig
- SSL/TLS configuration.
Enums§
- Connection
Error - Errors that can occur during connection string parsing.
- Driver
- Database driver type.
- SslMode
- SSL/TLS mode for connections.
Traits§
- EnvSource
- Source for environment variables.
Type Aliases§
- Connection
Result - Result type for connection operations.