Make Uuid a datatype in PostgreSQL dialect

This commit is contained in:
Jovansonlee Cesar 2018-09-29 13:50:33 +08:00
parent da153bf848
commit 639f01d4e7
5 changed files with 11 additions and 2 deletions

View file

@ -20,3 +20,4 @@ path = "src/lib.rs"
[dependencies]
log = "0.4.5"
chrono = "0.4.6"
uuid = "0.7.1"

View file

@ -528,6 +528,7 @@ impl Dialect for PostgreSqlDialect {
"PRIMARY",
"KEY",
"UNIQUE",
"UUID",
];
}

View file

@ -38,6 +38,7 @@
#[macro_use]
extern crate log;
extern crate chrono;
extern crate uuid;
pub mod dialect;
pub mod sqlast;

View file

@ -24,6 +24,8 @@ use chrono::{NaiveDate,
Utc,
};
use uuid::Uuid;
/// SQL Abstract Syntax Tree (AST)
#[derive(Debug, Clone, PartialEq)]
pub enum ASTNode {
@ -132,6 +134,7 @@ pub enum Value{
Double(f64),
/// Unquoted string
String(String),
Uuid(Uuid),
/// 'string value'
SingleQuotedString(String),
/// "string value"
@ -188,6 +191,8 @@ pub enum SQLType {
Char(Option<usize>),
/// Variable-length character type e.g. VARCHAR(10)
Varchar(Option<usize>),
/// Uuid value
Uuid,
/// Large character object e.g. CLOB(1000)
Clob(usize),
/// Fixed-length binary type e.g. BINARY(10)

View file

@ -758,6 +758,7 @@ impl Parser {
Ok(SQLType::Char(self.parse_optional_precision()?))
}
}
"UUID" => Ok(SQLType::Uuid),
"DATE" => Ok(SQLType::Date),
"TIMESTAMP" => if self.parse_keyword("WITH"){
if self.parse_keywords(vec!["TIME","ZONE"]){
@ -1562,14 +1563,14 @@ mod tests {
let c_name = &columns[0];
assert_eq!("settings_id", c_name.name);
assert_eq!(SQLType::Custom("uuid".into()), c_name.data_type);
assert_eq!(SQLType::Uuid, c_name.data_type);
assert_eq!(false, c_name.allow_null);
assert_eq!(true, c_name.is_primary);
assert_eq!(false, c_name.is_unique);
let c_name = &columns[1];
assert_eq!("user_id", c_name.name);
assert_eq!(SQLType::Custom("uuid".into()), c_name.data_type);
assert_eq!(SQLType::Uuid, c_name.data_type);
assert_eq!(true, c_name.allow_null);
assert_eq!(false, c_name.is_primary);
assert_eq!(true, c_name.is_unique);