diff --git a/server-api/db/src/lib.rs b/server-api/db/src/lib.rs new file mode 100644 index 0000000..e0564ea --- /dev/null +++ b/server-api/db/src/lib.rs @@ -0,0 +1,42 @@ +mod member; +mod common; + +use std::vec::Vec; +use mysql_async::Conn; +use mysql_async::prelude::Queryable; // lets us use the special dsl provided +use mysql_async::params as sql_params; + +pub type BigInt = i64; +pub type UBigInt = u64; + +pub type Integer = i32; +pub type UInteger = u32; + +pub type VarChar = String; + +pub enum Response { + // A set of rows collected + Set(Vec), + // Single row collected + Row(T), + // Nothing was found -> for select/update/delete's + Empty, + // Generic success for things like update/delete's + Success, + // Duplicate keys can sometimes fuck us over for inserts/update(why tf tho) + Duplicate, + // Not sure what this will be used for but maybe its useful at some point + Other(&'static str) +} + + +#[macro_export] +macro_rules! fetch_row { + ($table:literal, $col:literal, $key:expr, $rtype:ty,$conn:expr) => { + let lib_str = format!("SELECT * FROM {} WHERE {} = :{}", $table, $col, $col); + let (_, $rtype) = $conn.first_exec!(lib_str, sql_params{ + $col => $key, + }); + } +} +