+New .add method for db::Invites
+New new() method to reduce on eye clutter
This commit is contained in:
parent
9fac3aa117
commit
39a4d2a247
@ -114,3 +114,27 @@ impl FromDB<Invite, bool> for Invite {
|
||||
}
|
||||
}
|
||||
|
||||
impl Invite {
|
||||
pub fn new(uses: Option<i64>, expires: bool) -> Invite {
|
||||
use chrono::Utc;
|
||||
|
||||
Invite {
|
||||
id: (Utc::now() + chrono::Duration::minutes(30)).timestamp(),
|
||||
uses: uses,
|
||||
expires: expires
|
||||
}
|
||||
}
|
||||
pub async fn add(&self, p: &Pool) -> Result<(), SqlError> {
|
||||
let conn = p.get_conn().await?;
|
||||
|
||||
conn.prep_exec(
|
||||
"INSERT INTO invites (id, uses, expires)
|
||||
VALUES (:id, :uses, :expires)", params!{
|
||||
"id" => self.id,
|
||||
"uses" => self.uses,
|
||||
"expires" => self.expires
|
||||
}).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user