Improve database TYPE clause definitions
This commit is contained in:
parent
876a1e581e
commit
b85e983ce7
1 changed files with 39 additions and 20 deletions
|
@ -14,11 +14,15 @@ pub enum Kind {
|
||||||
Array,
|
Array,
|
||||||
Bool,
|
Bool,
|
||||||
Datetime,
|
Datetime,
|
||||||
|
Decimal,
|
||||||
|
Duration,
|
||||||
|
Float,
|
||||||
|
Int,
|
||||||
Number,
|
Number,
|
||||||
Object,
|
Object,
|
||||||
String,
|
String,
|
||||||
Geometry(String),
|
|
||||||
Record(Vec<Table>),
|
Record(Vec<Table>),
|
||||||
|
Geometry(Vec<String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Kind {
|
impl Default for Kind {
|
||||||
|
@ -34,14 +38,22 @@ impl fmt::Display for Kind {
|
||||||
Kind::Array => write!(f, "array"),
|
Kind::Array => write!(f, "array"),
|
||||||
Kind::Bool => write!(f, "bool"),
|
Kind::Bool => write!(f, "bool"),
|
||||||
Kind::Datetime => write!(f, "datetime"),
|
Kind::Datetime => write!(f, "datetime"),
|
||||||
|
Kind::Decimal => write!(f, "decimal"),
|
||||||
|
Kind::Duration => write!(f, "duration"),
|
||||||
|
Kind::Float => write!(f, "float"),
|
||||||
|
Kind::Int => write!(f, "int"),
|
||||||
Kind::Number => write!(f, "number"),
|
Kind::Number => write!(f, "number"),
|
||||||
Kind::Object => write!(f, "object"),
|
Kind::Object => write!(f, "object"),
|
||||||
Kind::String => write!(f, "string"),
|
Kind::String => write!(f, "string"),
|
||||||
Kind::Geometry(v) => write!(f, "geometry({})", v),
|
|
||||||
Kind::Record(v) => write!(
|
Kind::Record(v) => write!(
|
||||||
f,
|
f,
|
||||||
"record({})",
|
"record({})",
|
||||||
v.iter().map(|ref v| format!("{}", v)).collect::<Vec<_>>().join(", ")
|
v.iter().map(|ref v| v.to_string()).collect::<Vec<_>>().join(", ")
|
||||||
|
),
|
||||||
|
Kind::Geometry(v) => write!(
|
||||||
|
f,
|
||||||
|
"geometry({})",
|
||||||
|
v.iter().map(|ref v| v.to_string()).collect::<Vec<_>>().join(", ")
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,6 +65,10 @@ pub fn kind(i: &str) -> IResult<&str, Kind> {
|
||||||
map(tag("array"), |_| Kind::Array),
|
map(tag("array"), |_| Kind::Array),
|
||||||
map(tag("bool"), |_| Kind::Bool),
|
map(tag("bool"), |_| Kind::Bool),
|
||||||
map(tag("datetime"), |_| Kind::Datetime),
|
map(tag("datetime"), |_| Kind::Datetime),
|
||||||
|
map(tag("decimal"), |_| Kind::Decimal),
|
||||||
|
map(tag("duration"), |_| Kind::Duration),
|
||||||
|
map(tag("float"), |_| Kind::Float),
|
||||||
|
map(tag("int"), |_| Kind::Int),
|
||||||
map(tag("number"), |_| Kind::Number),
|
map(tag("number"), |_| Kind::Number),
|
||||||
map(tag("object"), |_| Kind::Object),
|
map(tag("object"), |_| Kind::Object),
|
||||||
map(tag("string"), |_| Kind::String),
|
map(tag("string"), |_| Kind::String),
|
||||||
|
@ -61,23 +77,6 @@ pub fn kind(i: &str) -> IResult<&str, Kind> {
|
||||||
))(i)
|
))(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn geometry(i: &str) -> IResult<&str, String> {
|
|
||||||
let (i, _) = tag("geometry")(i)?;
|
|
||||||
let (i, _) = char('(')(i)?;
|
|
||||||
let (i, v) = alt((
|
|
||||||
tag("feature"),
|
|
||||||
tag("point"),
|
|
||||||
tag("line"),
|
|
||||||
tag("polygon"),
|
|
||||||
tag("multipoint"),
|
|
||||||
tag("multiline"),
|
|
||||||
tag("multipolygon"),
|
|
||||||
tag("collection"),
|
|
||||||
))(i)?;
|
|
||||||
let (i, _) = char(')')(i)?;
|
|
||||||
Ok((i, String::from(v)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn record(i: &str) -> IResult<&str, Vec<Table>> {
|
fn record(i: &str) -> IResult<&str, Vec<Table>> {
|
||||||
let (i, _) = tag("record")(i)?;
|
let (i, _) = tag("record")(i)?;
|
||||||
let (i, _) = char('(')(i)?;
|
let (i, _) = char('(')(i)?;
|
||||||
|
@ -85,3 +84,23 @@ fn record(i: &str) -> IResult<&str, Vec<Table>> {
|
||||||
let (i, _) = char(')')(i)?;
|
let (i, _) = char(')')(i)?;
|
||||||
Ok((i, v))
|
Ok((i, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn geometry(i: &str) -> IResult<&str, Vec<String>> {
|
||||||
|
let (i, _) = tag("geometry")(i)?;
|
||||||
|
let (i, _) = char('(')(i)?;
|
||||||
|
let (i, v) = many1(map(
|
||||||
|
alt((
|
||||||
|
tag("feature"),
|
||||||
|
tag("point"),
|
||||||
|
tag("line"),
|
||||||
|
tag("polygon"),
|
||||||
|
tag("multipoint"),
|
||||||
|
tag("multiline"),
|
||||||
|
tag("multipolygon"),
|
||||||
|
tag("collection"),
|
||||||
|
)),
|
||||||
|
String::from,
|
||||||
|
))(i)?;
|
||||||
|
let (i, _) = char(')')(i)?;
|
||||||
|
Ok((i, v))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue