mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-14 07:52:02 +00:00
Make Uuid a datatype in PostgreSQL dialect
This commit is contained in:
parent
da153bf848
commit
639f01d4e7
5 changed files with 11 additions and 2 deletions
|
@ -20,3 +20,4 @@ path = "src/lib.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.5"
|
log = "0.4.5"
|
||||||
chrono = "0.4.6"
|
chrono = "0.4.6"
|
||||||
|
uuid = "0.7.1"
|
||||||
|
|
|
@ -528,6 +528,7 @@ impl Dialect for PostgreSqlDialect {
|
||||||
"PRIMARY",
|
"PRIMARY",
|
||||||
"KEY",
|
"KEY",
|
||||||
"UNIQUE",
|
"UNIQUE",
|
||||||
|
"UUID",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
|
extern crate uuid;
|
||||||
|
|
||||||
pub mod dialect;
|
pub mod dialect;
|
||||||
pub mod sqlast;
|
pub mod sqlast;
|
||||||
|
|
|
@ -24,6 +24,8 @@ use chrono::{NaiveDate,
|
||||||
Utc,
|
Utc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
/// SQL Abstract Syntax Tree (AST)
|
/// SQL Abstract Syntax Tree (AST)
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum ASTNode {
|
pub enum ASTNode {
|
||||||
|
@ -132,6 +134,7 @@ pub enum Value{
|
||||||
Double(f64),
|
Double(f64),
|
||||||
/// Unquoted string
|
/// Unquoted string
|
||||||
String(String),
|
String(String),
|
||||||
|
Uuid(Uuid),
|
||||||
/// 'string value'
|
/// 'string value'
|
||||||
SingleQuotedString(String),
|
SingleQuotedString(String),
|
||||||
/// "string value"
|
/// "string value"
|
||||||
|
@ -188,6 +191,8 @@ pub enum SQLType {
|
||||||
Char(Option<usize>),
|
Char(Option<usize>),
|
||||||
/// Variable-length character type e.g. VARCHAR(10)
|
/// Variable-length character type e.g. VARCHAR(10)
|
||||||
Varchar(Option<usize>),
|
Varchar(Option<usize>),
|
||||||
|
/// Uuid value
|
||||||
|
Uuid,
|
||||||
/// Large character object e.g. CLOB(1000)
|
/// Large character object e.g. CLOB(1000)
|
||||||
Clob(usize),
|
Clob(usize),
|
||||||
/// Fixed-length binary type e.g. BINARY(10)
|
/// Fixed-length binary type e.g. BINARY(10)
|
||||||
|
|
|
@ -758,6 +758,7 @@ impl Parser {
|
||||||
Ok(SQLType::Char(self.parse_optional_precision()?))
|
Ok(SQLType::Char(self.parse_optional_precision()?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"UUID" => Ok(SQLType::Uuid),
|
||||||
"DATE" => Ok(SQLType::Date),
|
"DATE" => Ok(SQLType::Date),
|
||||||
"TIMESTAMP" => if self.parse_keyword("WITH"){
|
"TIMESTAMP" => if self.parse_keyword("WITH"){
|
||||||
if self.parse_keywords(vec!["TIME","ZONE"]){
|
if self.parse_keywords(vec!["TIME","ZONE"]){
|
||||||
|
@ -1562,14 +1563,14 @@ mod tests {
|
||||||
|
|
||||||
let c_name = &columns[0];
|
let c_name = &columns[0];
|
||||||
assert_eq!("settings_id", c_name.name);
|
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!(false, c_name.allow_null);
|
||||||
assert_eq!(true, c_name.is_primary);
|
assert_eq!(true, c_name.is_primary);
|
||||||
assert_eq!(false, c_name.is_unique);
|
assert_eq!(false, c_name.is_unique);
|
||||||
|
|
||||||
let c_name = &columns[1];
|
let c_name = &columns[1];
|
||||||
assert_eq!("user_id", c_name.name);
|
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!(true, c_name.allow_null);
|
||||||
assert_eq!(false, c_name.is_primary);
|
assert_eq!(false, c_name.is_primary);
|
||||||
assert_eq!(true, c_name.is_unique);
|
assert_eq!(true, c_name.is_unique);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue