Skip to main content

systemprompt_users/repository/banned_ip/
mod.rs

1mod listing;
2mod queries;
3mod types;
4
5use std::sync::Arc;
6
7use anyhow::Result;
8use sqlx::PgPool;
9use systemprompt_database::DbPool;
10
11pub use types::{BanDuration, BanIpParams, BanIpWithMetadataParams, BannedIp};
12
13#[derive(Clone, Debug)]
14pub struct BannedIpRepository {
15    pool: Arc<PgPool>,
16    write_pool: Arc<PgPool>,
17}
18
19impl BannedIpRepository {
20    pub fn new(db: &DbPool) -> Result<Self> {
21        let pool = db.pool_arc()?;
22        let write_pool = db.write_pool_arc()?;
23        Ok(Self { pool, write_pool })
24    }
25
26    pub fn from_pool(pool: Arc<PgPool>) -> Self {
27        let write_pool = Arc::clone(&pool);
28        Self { pool, write_pool }
29    }
30}