Module connection

Module connection 

Source
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 hostname

Structs§

ConnectionOptions
Common connection options.
ConnectionString
Connection string parser.
DatabaseConfig
Complete database configuration.
DatabaseConfigBuilder
Builder for database configuration.
EnvExpander
Expands environment variables in strings.
MultiDatabaseConfig
Configuration for multiple databases.
MySqlOptions
MySQL-specific options.
ParsedUrl
A parsed database URL.
PoolConfig
Complete pool configuration combining connection and pool options.
PoolOptions
Pool options.
PostgresOptions
PostgreSQL-specific options.
SqliteOptions
SQLite-specific options.
SslConfig
SSL/TLS configuration.

Enums§

ConnectionError
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§

ConnectionResult
Result type for connection operations.