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, DeclaredUserRow, DeclaredUserWrite,
37    EnsuredServiceAccount, MERGE_EXCLUDED_SECURITY_TABLES, MergeResult, NewServiceAccount,
38    PurgeCount, UpdateUserParams,
39};
40
41use sqlx::PgPool;
42use std::sync::Arc;
43use systemprompt_database::DbPool;
44
45const MAX_PAGE_SIZE: i64 = 100;
46
47#[derive(Debug, Clone)]
48pub struct UserRepository {
49    pool: Arc<PgPool>,
50    write_pool: Arc<PgPool>,
51}
52
53impl UserRepository {
54    pub fn new(db: &DbPool) -> Self {
55        let pool = db.pool();
56        let write_pool = db.write_pool();
57        Self { pool, write_pool }
58    }
59}