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, rate-limit-bucket and session repositories live
6//! alongside 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 api_key_session;
15mod banned_ip;
16mod device_cert;
17mod federated_identity;
18mod rate_limit_bucket;
19mod role_directory;
20mod session;
21mod session_traffic;
22mod sso_login_events;
23mod user;
24
25pub use api_key::CreateApiKeyParams;
26pub use banned_ip::{
27    BanDuration, BanIpParams, BanIpWithMetadataParams, BannedIp, BannedIpRepository,
28};
29pub use device_cert::EnrollDeviceCertParams;
30pub use rate_limit_bucket::UserRateLimitBucketRepository;
31pub use role_directory::UsersRoleDirectory;
32pub use session::SessionRepository;
33pub use session_traffic::SessionTrafficRollupRepository;
34pub use sso_login_events::{NewSsoLoginEvent, SsoLoginEvent, SsoLoginEventRepository};
35pub use user::{
36    ArchiveOutcome, ArchiveParams, ArchiveState, EnsuredServiceAccount,
37    MERGE_EXCLUDED_SECURITY_TABLES, MergeResult, NewServiceAccount, PurgeCount, UpdateUserParams,
38};
39
40use sqlx::PgPool;
41use std::sync::Arc;
42use systemprompt_database::DbPool;
43
44const MAX_PAGE_SIZE: i64 = 100;
45
46#[derive(Debug, Clone)]
47pub struct UserRepository {
48    pool: Arc<PgPool>,
49    write_pool: Arc<PgPool>,
50}
51
52impl UserRepository {
53    pub fn new(db: &DbPool) -> Self {
54        let pool = db.pool();
55        let write_pool = db.write_pool();
56        Self { pool, write_pool }
57    }
58}