Skip to main content

systemprompt_users/repository/
mod.rs

1//! Database access layer for the users domain.
2//!
3//! [`UserRepository`] holds the read and write pools and implements user CRUD,
4//! sessions, and federated identity across the `user` submodule; the API-key,
5//! device-cert, and banned-IP repositories live alongside it. Mutating
6//! operations take typed parameter structs ([`UpdateUserParams`],
7//! [`CreateApiKeyParams`], [`EnrollDeviceCertParams`], [`BanIpParams`]).
8
9mod api_key;
10mod banned_ip;
11mod device_cert;
12mod federated_identity;
13mod user;
14
15pub use api_key::CreateApiKeyParams;
16pub use banned_ip::{
17    BanDuration, BanIpParams, BanIpWithMetadataParams, BannedIp, BannedIpRepository,
18};
19pub use device_cert::EnrollDeviceCertParams;
20pub use user::{MergeResult, UpdateUserParams};
21
22use crate::error::Result;
23use sqlx::PgPool;
24use std::sync::Arc;
25use systemprompt_database::DbPool;
26
27const MAX_PAGE_SIZE: i64 = 100;
28
29#[derive(Debug, Clone)]
30pub struct UserRepository {
31    pool: Arc<PgPool>,
32    write_pool: Arc<PgPool>,
33}
34
35impl UserRepository {
36    pub fn new(db: &DbPool) -> Result<Self> {
37        let pool = db.pool_arc()?;
38        let write_pool = db.write_pool_arc()?;
39        Ok(Self { pool, write_pool })
40    }
41}