DbInvites .filter method
! untested
This commit is contained in:
parent
562377d6e2
commit
960abac7d9
@ -19,7 +19,7 @@ pub struct Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl FromDB<Message> for Message {
|
impl FromDB<Message, (BigInt, UBigInt)> for Message {
|
||||||
type Row = Option<(UBigInt, BigInt, VarChar, UBigInt, VarChar)>;
|
type Row = Option<(UBigInt, BigInt, VarChar, UBigInt, VarChar)>;
|
||||||
|
|
||||||
async fn get(p: &Pool, id: UBigInt) -> Response<Self> {
|
async fn get(p: &Pool, id: UBigInt) -> Response<Self> {
|
||||||
@ -78,4 +78,37 @@ impl FromDB<Message> for Message {
|
|||||||
}
|
}
|
||||||
return Response::Other(no_conn!("Message::FromDB::update"))
|
return Response::Other(no_conn!("Message::FromDB::update"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn filter(p: &Pool, (time, channel_id): (BigInt, UBigInt)) -> Response<Self> {
|
||||||
|
//! FIlter happens via unix_timestamp and channel_id respectively
|
||||||
|
if let Ok(conn) = p.get_conn().await {
|
||||||
|
let q = "SELECT id, time, content, author_id";
|
||||||
|
if let Ok(query)= conn.prep_exec(q, params!{"time" => time, "cid" => channel_id}).await {
|
||||||
|
let mapping_r = query.map_and_drop(|row| {
|
||||||
|
let (id, time, content, uid): (UBigInt, BigInt, VarChar, UBigInt) =
|
||||||
|
mysql_async::from_row(row);
|
||||||
|
|
||||||
|
Message {
|
||||||
|
id: id,
|
||||||
|
time: time,
|
||||||
|
content: content,
|
||||||
|
author_id: uid,
|
||||||
|
channel_name: "".into() // no point at this point tbh
|
||||||
|
}
|
||||||
|
}).await;
|
||||||
|
|
||||||
|
match mapping_r {
|
||||||
|
Ok((_, messages)) => Response::Set(messages),
|
||||||
|
Err(_) => Response::Other(sql_err!("db::Message::filter"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Response::Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Response::Other(no_conn!("db::Message::filter"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user