Removed sql_traits module as it was merely a stepping stone module

Channel struct now adpots a from_tup method and can be seen in use in get_channels_vec
This commit is contained in:
shockrah 2020-06-02 22:10:28 -07:00
parent 08e5b87ba4
commit 4f71e566c3
2 changed files with 3 additions and 18 deletions

View File

@ -4,8 +4,6 @@ use mysql_async::{Conn, Pool};
use mysql_async::error::Error; use mysql_async::error::Error;
use mysql_async::prelude::Queryable; use mysql_async::prelude::Queryable;
use crate::sql_traits::DBTrait;
enum ChannelType { enum ChannelType {
Voice, Voice,
Text, Text,
@ -37,8 +35,8 @@ struct Channel {
kind: ChannelType kind: ChannelType
} }
impl DBTrait for Channel { impl Channel {
fn from(tup: (i32, String, String, i32)) -> Channel { fn from_tup(tup: (i32, String, String, i32)) -> Channel {
Channel { Channel {
id: tup.0, id: tup.0,
name: tup.1, name: tup.1,
@ -61,12 +59,7 @@ async fn get_channels_vec(conn: Conn) -> Result<Vec<Channel>, Error> {
let rows_db = conn.prep_exec(r"SELECT * FROM channels", ()).await?; let rows_db = conn.prep_exec(r"SELECT * FROM channels", ()).await?;
let (_, rows) = rows_db.map_and_drop(|row| { let (_, rows) = rows_db.map_and_drop(|row| {
let (id, name, desc, kind): (i32, String, String, i32) = mysql_async::from_row(row); let (id, name, desc, kind): (i32, String, String, i32) = mysql_async::from_row(row);
Channel { Channel::from_tup((id, name, desc, kind))
id: id,
name: name,
description: desc,
kind: ChannelType::from_i32(kind)
}
}).await?; }).await?;
Ok(rows) Ok(rows)

View File

@ -1,8 +0,0 @@
// Module with some basic traits we supply for things that go in + out of
// mysql_async
pub trait DBTrait {
fn from(db_tup: (i32, String, String, i32)) -> Self;
fn as_json_str(&self) -> String;
}