kych

OAuth 2.0 API for Swiyu to enable Taler integration of Swiyu for KYC (experimental)
Log | Files | Refs | README | LICENSE

mod.rs (927B)


      1 // Database module for OAuth2 Gateway
      2 // Provides database connection pooling and business logic operations
      3 
      4 use sqlx::{PgPool, postgres::{PgConnectOptions, 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 /// * `options` - connection parameters, as parsed from the DATABASE option
     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(options: PgConnectOptions) -> Result<PgPool> {
     24     let pool = PgPoolOptions::new()
     25         .max_connections(10)
     26         .connect_with(options)
     27         .await
     28         .context("Failed to connect to PostgreSQL")?;
     29 
     30     tracing::info!("Database connection pool created");
     31     Ok(pool)
     32 }