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 role_directory;
19mod user;
20
21pub use api_key::CreateApiKeyParams;
22pub use banned_ip::{
23    BanDuration, BanIpParams, BanIpWithMetadataParams, BannedIp, BannedIpRepository,
24};
25pub use device_cert::EnrollDeviceCertParams;
26pub use rate_limit_bucket::UserRateLimitBucketRepository;
27pub use role_directory::UsersRoleDirectory;
28pub use user::{MERGE_EXCLUDED_SECURITY_TABLES, MergeResult, PurgeCount, UpdateUserParams};
29
30use crate::error::Result;
31use sqlx::PgPool;
32use std::sync::Arc;
33use systemprompt_database::DbPool;
34
35const MAX_PAGE_SIZE: i64 = 100;
36
37#[derive(Debug, Clone)]
38pub struct UserRepository {
39    pool: Arc<PgPool>,
40    write_pool: Arc<PgPool>,
41}
42
43impl UserRepository {
44    pub fn new(db: &DbPool) -> Result<Self> {
45        let pool = db.pool_arc()?;
46        let write_pool = db.write_pool_arc()?;
47        Ok(Self { pool, write_pool })
48    }
49}