mssql_quick/method/
msdel.rs1#[macro_export]
19macro_rules! msdel {
20 ($t:expr, {$k:tt: $v:expr}) => {{
21 fn type_of<T>(_: T) -> &'static str {
22 std::any::type_name::<T>()
23 }
24 let keys = $k.to_string();
25 let temp_v = $v;
26 let v_type = type_of(&temp_v);
27 let values = match v_type {
28 "&&str" | "&alloc::string::String" | "&&alloc::string::String" => {
29 let mut v_r = temp_v.to_string();
30 v_r = v_r.replace("'", "''");
31 "N'".to_string() + &v_r + "'"
32 }
33 "&u8" | "&u16" | "&u32" | "&u64" | "&u128" | "&usize" | "&i8" | "&i16" | "&i32"
34 | "&i64" | "&i128" | "&isize" | "&f32" | "&f64" | "&f128" | "&bool" => {
35 temp_v.to_string() + ""
36 }
37 "&&u8" | "&&u16" | "&&u32" | "&&u64" | "&&u128" | "&&usize" | "&&i8" | "&&i16"
38 | "&&i32" | "&&i64" | "&&i128" | "&&isize" | "&&f32" | "&&f64" | "&&f128"
39 | "&&bool" => temp_v.to_string() + "",
40 _ => "".to_string(),
41 };
42
43 let sql: String =
44 "DELETE FROM ".to_string() + $t + " WHERE " + keys.as_str() + "=" + values.as_str();
45
46 sql
47 }};
48
49 ($t:expr, $v: expr) => {{
50 fn type_of<T>(_: T) -> &'static str {
51 std::any::type_name::<T>()
52 }
53 let temp_v = $v;
54 let v_type = type_of(&temp_v);
55 let values = match v_type {
56 "&&str" | "&alloc::string::String" | "&&alloc::string::String" => {
57 let mut v_r = temp_v.to_string();
58 v_r = v_r.replace("'", "''");
59 "N'".to_string() + &v_r + "'"
60 }
61 "&u8" | "&u16" | "&u32" | "&u64" | "&u128" | "&usize" | "&i8" | "&i16" | "&i32"
62 | "&i64" | "&i128" | "&isize" | "&f32" | "&f64" | "&f128" | "&bool" => {
63 temp_v.to_string() + ""
64 }
65 "&&u8" | "&&u16" | "&&u32" | "&&u64" | "&&u128" | "&&usize" | "&&i8" | "&&i16"
66 | "&&i32" | "&&i64" | "&&i128" | "&&isize" | "&&f32" | "&&f64" | "&&f128"
67 | "&&bool" => temp_v.to_string() + "",
68 _ => "".to_string(),
69 };
70
71 let sql: String = "DELETE FROM ".to_string() + $t + " WHERE id=" + values.as_str();
72
73 sql
74 }};
75}