main lib interface for userland code in main project
This commit is contained in:
parent
d91666658b
commit
4e591d8318
42
server-api/db/src/lib.rs
Normal file
42
server-api/db/src/lib.rs
Normal file
@ -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<T> {
|
||||||
|
// A set of rows collected
|
||||||
|
Set(Vec<T>),
|
||||||
|
// 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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user