mod.rs (957B)
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 pub mod notification_webhooks; 12 13 /// Create a PostgreSQL connection pool 14 /// 15 /// # Arguments 16 /// * `database_url` - PostgreSQL connection string (e.g., "postgresql://user:pass@localhost/dbname") 17 /// 18 /// # Returns 19 /// Connection pool ready for use 20 /// 21 /// # Notes 22 /// Assumes the database schema is already set up via migrations. 23 /// Run scripts/setup_test_db.sh to initialize the database. 24 pub async fn create_pool(database_url: &str) -> Result<PgPool> { 25 let pool = PgPoolOptions::new() 26 .max_connections(10) 27 .connect(database_url) 28 .await 29 .context("Failed to connect to PostgreSQL")?; 30 31 tracing::info!("Database connection pool created"); 32 Ok(pool) 33 }