cyaxon_authifier/database/
definition.rs

1use crate::{
2	models::{Account, Invite, MFATicket, Session},
3	Result, Success,
4};
5
6use super::Migration;
7
8#[async_trait]
9pub trait AbstractDatabase: std::marker::Sync {
10	/// Run a database migration
11	async fn run_migration(&self, migration: Migration) -> Success;
12
13	/// Find account by id
14	async fn find_account(&self, id: &str) -> Result<Account>;
15
16	/// Find account by normalized email
17	async fn find_account_by_normalized_email(
18		&self,
19		normalized_email: &str,
20	) -> Result<Option<Account>>;
21
22	/// Find account with active pending email verification
23	async fn find_account_with_email_verification(&self, token: &str) -> Result<Account>;
24
25	/// Find account with active password reset
26	async fn find_account_with_password_reset(&self, token: &str) -> Result<Account>;
27
28	/// Find account with active deletion token
29	async fn find_account_with_deletion_token(&self, token: &str) -> Result<Account>;
30
31	/// Find invite by id
32	async fn find_invite(&self, id: &str) -> Result<Invite>;
33
34	/// Find session by id
35	async fn find_session(&self, id: &str) -> Result<Session>;
36
37	/// Find sessions by user id
38	async fn find_sessions(&self, user_id: &str) -> Result<Vec<Session>>;
39
40	/// Find sessions by user ids
41	async fn find_sessions_with_subscription(&self, user_ids: &[String]) -> Result<Vec<Session>>;
42
43	/// Find session by token
44	async fn find_session_by_token(&self, token: &str) -> Result<Option<Session>>;
45
46	/// Find ticket by token
47	async fn find_ticket_by_token(&self, token: &str) -> Result<Option<MFATicket>>;
48
49	// Save account
50	async fn save_account(&self, account: &Account) -> Success;
51
52	/// Save session
53	async fn save_session(&self, session: &Session) -> Success;
54
55	/// Save invite
56	async fn save_invite(&self, invite: &Invite) -> Success;
57
58	/// Save ticket
59	async fn save_ticket(&self, ticket: &MFATicket) -> Success;
60
61	/// Delete session
62	async fn delete_session(&self, id: &str) -> Success;
63
64	/// Delete session
65	async fn delete_all_sessions(&self, user_id: &str, ignore: Option<String>) -> Success;
66
67	/// Delete ticket
68	async fn delete_ticket(&self, id: &str) -> Success;
69}