1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use serde_json::Value;
use crate::db::DriverType;
use crate::Result;

///the stmt replace str convert
pub trait StmtConvert {
    fn stmt_convert(&self, index: usize) -> String;
}

impl StmtConvert for DriverType {
    fn stmt_convert(&self, index: usize) -> String {
        match &self {
            DriverType::Postgres => {
                format!("${}", index + 1)
            }
            DriverType::Mysql => {
                "?".to_string()
            }
            DriverType::Sqlite => {
                "?".to_string()
            }
            DriverType::Mssql => {
                format!("@p{}", index + 1)
            }
            DriverType::None => {
                panic!("[rbatis] un support none for driver type!")
            }
        }
    }
}

///json convert
pub trait JsonCodec {
    /// to an json value
    fn try_to_json(self) -> Result<Value>;
}

///json convert
pub trait RefJsonCodec {
    /// to an json value
    fn try_to_json(&self) -> Result<Value>;
}

///result convert
pub trait ResultCodec<T>{
    fn into_result(self) -> Result<T>;
}