Skip to main content

revolt_database/models/users/
ops.rs

1use revolt_result::Result;
2
3use crate::{FieldsUser, PartialUser, RelationshipStatus, User};
4
5#[cfg(feature = "mongodb")]
6mod mongodb;
7mod reference;
8
9#[async_trait]
10pub trait AbstractUsers: Sync + Send {
11    /// Insert a new user into the database
12    async fn insert_user(&self, user: &User) -> Result<()>;
13
14    /// Fetch a user from the database
15    async fn fetch_user(&self, id: &str) -> Result<User>;
16
17    /// Fetch a user from the database by their username
18    async fn fetch_user_by_username(&self, username: &str, discriminator: &str) -> Result<User>;
19
20    /// Fetch multiple users by their ids
21    async fn fetch_users<'a>(&self, ids: &'a [String]) -> Result<Vec<User>>;
22
23    /// Fetch all discriminators in use for a username
24    async fn fetch_discriminators_in_use(&self, username: &str) -> Result<Vec<String>>;
25
26    /// Fetch ids of users that both users are friends with
27    async fn fetch_mutual_user_ids(&self, user_a: &str, user_b: &str) -> Result<Vec<String>>;
28
29    /// Fetch ids of channels that both users are in
30    async fn fetch_mutual_channel_ids(&self, user_a: &str, user_b: &str) -> Result<Vec<String>>;
31
32    /// Fetch ids of servers that both users share
33    async fn fetch_mutual_server_ids(&self, user_a: &str, user_b: &str) -> Result<Vec<String>>;
34
35    /// Update a user by their id given some data
36    async fn update_user(
37        &self,
38        id: &str,
39        user: &PartialUser,
40        remove: Vec<FieldsUser>,
41    ) -> Result<()>;
42
43    /// Set relationship with another user
44    ///
45    /// This should use pull_relationship if relationship is None.
46    async fn set_relationship(
47        &self,
48        user_id: &str,
49        target_id: &str,
50        relationship: &RelationshipStatus,
51    ) -> Result<()>;
52
53    /// Remove relationship with another user
54    async fn pull_relationship(&self, user_id: &str, target_id: &str) -> Result<()>;
55
56    /// Delete a user by their id
57    async fn delete_user(&self, id: &str) -> Result<()>;
58
59    /// Removes all relationships with the user from the list of users
60    async fn clear_user_relationships(&self, target_id: &str, user_ids: Vec<String>) -> Result<()>;
61}