mod.rs (926B)
1 // Database module for OAuth2 Gateway 2 // Provides database connection pooling and business logic operations 3 4 use sqlx::{PgPool, postgres::PgPoolOptions}; 5 use anyhow::{Result, Context}; 6 7 pub mod sessions; 8 pub mod tokens; 9 pub mod clients; 10 pub mod authorization_codes; 11 12 /// Create a PostgreSQL connection pool 13 /// 14 /// # Arguments 15 /// * `database_url` - PostgreSQL connection string (e.g., "postgresql://user:pass@localhost/dbname") 16 /// 17 /// # Returns 18 /// Connection pool ready for use 19 /// 20 /// # Notes 21 /// Assumes the database schema is already set up via migrations. 22 /// Run scripts/setup_test_db.sh to initialize the database. 23 pub async fn create_pool(database_url: &str) -> Result<PgPool> { 24 let pool = PgPoolOptions::new() 25 .max_connections(10) 26 .connect(database_url) 27 .await 28 .context("Failed to connect to PostgreSQL")?; 29 30 tracing::info!("Database connection pool created"); 31 Ok(pool) 32 }