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//!
9//! Copyright (c) systemprompt.io — Business Source License 1.1.
10//! See <https://systemprompt.io> for licensing details.
11
12mod api_key;
13mod banned_ip;
14mod device_cert;
15mod federated_identity;
16mod user;
17
18pub use api_key::CreateApiKeyParams;
19pub use banned_ip::{
20    BanDuration, BanIpParams, BanIpWithMetadataParams, BannedIp, BannedIpRepository,
21};
22pub use device_cert::EnrollDeviceCertParams;
23pub use user::{MergeResult, UpdateUserParams};
24
25use crate::error::Result;
26use sqlx::PgPool;
27use std::sync::Arc;
28use systemprompt_database::DbPool;
29
30const MAX_PAGE_SIZE: i64 = 100;
31
32#[derive(Debug, Clone)]
33pub struct UserRepository {
34    pool: Arc<PgPool>,
35    write_pool: Arc<PgPool>,
36}
37
38impl UserRepository {
39    pub fn new(db: &DbPool) -> Result<Self> {
40        let pool = db.pool_arc()?;
41        let write_pool = db.write_pool_arc()?;
42        Ok(Self { pool, write_pool })
43    }
44}