From 471639a635beb86b74c44930e30a5b801f7765a5 Mon Sep 17 00:00:00 2001 From: shockrah Date: Thu, 17 Sep 2020 18:55:27 -0700 Subject: [PATCH] file for channels db api --- server-api/db/src/channels.rs | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 server-api/db/src/channels.rs diff --git a/server-api/db/src/channels.rs b/server-api/db/src/channels.rs new file mode 100644 index 0000000..260d9ad --- /dev/null +++ b/server-api/db/src/channels.rs @@ -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, + kind: Integer +} + +#[async_trait] +impl FromDB for Channel { + // id name desc kind + type Row = Option<(UBigInt, VarChar, Option, Integer)>; + + async fn get(p: &Pool, id: UBigInt) -> Response { + 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 { + unimplemented!() + } + + async fn delete(p: &Pool, id: UBigInt) -> Response { + unimplemented!() + } +}