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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use crate::commands::{from_op, TuringOp};

/// ### Handles all queries releated to fields
/// ```rust
/// #[derive(Debug, Clone)]
/// pub struct DbQuery {
///     db: String,
/// }
/// ```
#[derive(Debug, Clone)]
pub struct DbQuery {
    db: String,
}

impl<'tp> DbQuery {
    /// ### Initialize a new empty database
    /// #### Usage
    /// ```rust
    /// use crate::DatabaseQuery;
    ///
    /// Database::new().await
    /// ```
    pub async fn new() -> Self {
        Self {
            db: Default::default(),
        }
    }
    /// ### Add a database name
    /// #### Usage
    /// ```rust
    /// use crate::DatabaseQuery;
    ///
    /// let mut foo = Database::new().await;
    /// foo.db("db_name").await;
    /// ```
    pub async fn db(&mut self, name: &str) -> &Self {
        self.db = name.into();

        self
    }
    /// ### Creates a new a database in a repo
    /// #### Usage
    /// ```rust
    /// use crate::DatabaseQuery;
    ///
    /// let mut foo = DatabaseQuery::new().await;
    /// foo
    ///   .db("db_name").await
    ///   .create().await
    /// ```
    pub async fn create(&self) -> Vec<u8> {
        let mut packet = from_op(&TuringOp::DbCreate).await.to_vec();
        packet.extend_from_slice(self.db.as_bytes());

        packet
    }
    /// ### Creates a new a database in a repo
    /// #### Usage
    /// ```rust
    /// use crate::DatabaseQuery;
    ///
    /// let mut foo = DatabaseQuery::new().await;
    /// foo
    ///   .db("db_name").await
    ///   .drop().await
    /// ```
    pub async fn drop(&self) -> Vec<u8> {
        let mut packet = from_op(&TuringOp::DbDrop).await.to_vec();
        packet.extend_from_slice(self.db.as_bytes());

        packet
    }
    /// ### List all databases in a repo
    /// #### Usage
    /// ```rust
    /// use crate::DatabaseQuery;
    ///
    /// let mut foo = DatabaseQuery::new().await;
    /// foo.list().await
    /// ```
    pub async fn list(&self) -> &'tp [u8] {
        from_op(&TuringOp::DbList).await
    }
}