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
use crate::table_sync::ColumMapper;
use rbs::Value;

pub struct PGTableMapper {}
impl ColumMapper for PGTableMapper {
    fn get_column(&self, _column: &str, v: &Value) -> String {
        match v {
            Value::Null => "NULL".to_string(),
            Value::Bool(_) => "BOOLEAN".to_string(),
            Value::I32(_) => "INTEGER".to_string(),
            Value::I64(_) => "BIGINT".to_string(),
            Value::U32(_) => "INTEGER".to_string(),
            Value::U64(_) => "BIGINT".to_string(),
            Value::F32(_) => "REAL".to_string(),
            Value::F64(_) => "DOUBLE PRECISION".to_string(),
            Value::String(v) => {
                if v != "" {
                    v.to_string()
                } else {
                    "TEXT".to_string()
                }
            }
            Value::Binary(_) => "BYTEA".to_string(),
            Value::Array(_) => "JSON".to_string(),
            Value::Map(_) => "JSON".to_string(),
            Value::Ext(t, _v) => match *t {
                "Date" => "DATE".to_string(),
                "DateTime" => "TIMESTAMP".to_string(),
                "Time" => "TIME".to_string(),
                "Timestamp" => "TIMESTAMP".to_string(),
                "Decimal" => "NUMERIC".to_string(),
                "Json" => "JSON".to_string(),
                "Uuid" => "UUID".to_string(),
                _ => "NULL".to_string(),
            },
        }
    }
}