file for channels db api

This commit is contained in:
shockrah 2020-09-17 18:55:27 -07:00
parent d6571b17ca
commit 471639a635

View File

@ -0,0 +1,53 @@
use mysql_async::{params, Pool, Conn};
use mysql_async::prelude::Queryable;
use mysql_async::error::Error as SqlError;
use async_trait::async_trait;
use crate::{VarChar, UBigInt, Integer};
use crate::common::FromDB;
use crate::{no_conn, Response};
#[allow(dead_code)]
pub struct Channel {
id: UBigInt,
name: VarChar,
description: Option<VarChar>,
kind: Integer
}
#[async_trait]
impl FromDB<Channel> for Channel {
// id name desc kind
type Row = Option<(UBigInt, VarChar, Option<VarChar>, Integer)>;
async fn get(p: &Pool, id: UBigInt) -> Response<Channel> {
if let Ok(conn) = p.get_conn().await {
let q = "SELECT id, name, description, kind WHERE id = :id";
let result: Result<(Conn, Self::Row), SqlError> =
conn.first_exec(q, params!{"id" => id}).await;
if let Ok((_, row)) = result {
return match row {
Some(row) => Response::Row(Channel {
id: id,
name: row.1,
description: row.2,
kind: row.3
}),
None => Response::Empty
}
}
return Response::Other(no_conn!("Invite::FromDB::get fetch failed"));
}
return Response::Other(no_conn!("Invite::FromDB::get"));
}
async fn update(p: &Pool, row: Self) -> Response<Channel> {
unimplemented!()
}
async fn delete(p: &Pool, id: UBigInt) -> Response<Channel> {
unimplemented!()
}
}