package cn.edu.whu.boot.common.utils.collection;

import cn.edu.whu.boot.common.domain.CommonConstant;

import java.util.HashMap;
import java.util.Map;

/**
 * 工具类：将前端传进来的字段类型转换为 PostgreSql 数据库中的字段类型
 */
public class DbTypeMappingUtil{

    private static final Map<String, String> POSTGRESQL_DATA_TYPE_MAP = new HashMap<String, String>(){
        private static final long serialVersionUID = -2609965797767791136L;{
        put(CommonConstant.INTEGER, "integer");
        put(CommonConstant.STRING, "varchar(255)");
        put(CommonConstant.TEXT, "text");
        put(CommonConstant.BLOB, "text");
        put(CommonConstant.DATE, "timestamp");
        put(CommonConstant.LONG, "bigint");
        put(CommonConstant.DOUBLE, "double precision");
    }};

    public static String changeDataType(String rawDataType){
        if(POSTGRESQL_DATA_TYPE_MAP.containsKey(rawDataType)){
            return POSTGRESQL_DATA_TYPE_MAP.get(rawDataType);
        }
        return null;
    }
}
