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