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