Skip to main content

rbatis/plugin/table_sync/
sqlite_mapper.rs

1use crate::table_sync::ColumnMapper;
2use rbs::Value;
3
4pub struct SqliteTableMapper {}
5
6impl ColumnMapper for SqliteTableMapper {
7    fn driver_type(&self) -> String {
8        "sqlite".to_string()
9    }
10
11    fn get_column_type(&self, _column: &str, v: &Value) -> String {
12        match v {
13            Value::Null => "NULL".to_string(),
14            Value::Bool(_) => "BOOLEAN".to_string(),
15            Value::I32(_) => "INTEGER".to_string(),
16            Value::I64(_) => "INT8".to_string(),
17            Value::U32(_) => "INTEGER".to_string(),
18            Value::U64(_) => "INT8".to_string(),
19            Value::F32(_) => "DOUBLE".to_string(),
20            Value::F64(_) => "DOUBLE".to_string(),
21            Value::String(v) => {
22                if v != "" {
23                    v.to_string()
24                } else {
25                    "TEXT".to_string()
26                }
27            }
28            Value::Binary(_) => "BLOB".to_string(),
29            Value::Array(_) => "BLOB".to_string(),
30            Value::Map(_) => "BLOB".to_string(),
31            Value::Ext(t, _v) => match *t {
32                "Date" => "TEXT".to_string(),
33                "DateTime" => "TEXT".to_string(),
34                "Time" => "TEXT".to_string(),
35                "Timestamp" => "INT8".to_string(),
36                "Decimal" => "NUMERIC".to_string(),
37                "Json" => "BLOB".to_string(),
38                "Uuid" => "TEXT".to_string(),
39                _ => "NULL".to_string(),
40            },
41        }
42    }
43}