1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! SeaORM-backed TeamRepository implementation
//!
//! Stores `core::models::team::{Team, TeamMember}` as JSON snapshots in the
//! `teams` and `team_members` tables created by migration
//! `m20240301_000002_create_teams_table`. Works with both SQLite and
//! PostgreSQL backends via the live `SeaOrmDatabase` connection.
mod canonical;
mod conversions;
mod legacy_sync;
mod repository_impl;
use sea_orm::DbBackend;
use std::sync::Arc;
use super::types::{DatabaseBackendType, SeaOrmDatabase};
/// SeaORM-backed team repository (supports SQLite and PostgreSQL).
pub struct SeaOrmTeamRepository {
db: Arc<SeaOrmDatabase>,
}
impl SeaOrmTeamRepository {
/// Create a new repository wrapping the given database connection.
pub fn new(db: Arc<SeaOrmDatabase>) -> Self {
Self { db }
}
pub(super) fn backend(&self) -> DbBackend {
match self.db.backend_type {
DatabaseBackendType::PostgreSQL => DbBackend::Postgres,
DatabaseBackendType::SQLite => DbBackend::Sqlite,
}
}
/// Return the positional placeholder for parameter `n` (1-based).
pub(super) fn ph(&self, n: usize) -> String {
match self.db.backend_type {
DatabaseBackendType::PostgreSQL => format!("${}", n),
DatabaseBackendType::SQLite => "?".to_string(),
}
}
}