Implement SQL Group as a newtype tuple struct
This commit is contained in:
parent
ec6cfc4fef
commit
745fa4fd97
2 changed files with 13 additions and 30 deletions
|
@ -213,7 +213,7 @@ impl Iterator {
|
||||||
// Loop over each group clause
|
// Loop over each group clause
|
||||||
for group in groups.iter() {
|
for group in groups.iter() {
|
||||||
// Get the value at the path
|
// Get the value at the path
|
||||||
let val = obj.pick(&group.group);
|
let val = obj.pick(group);
|
||||||
// Set the value at the path
|
// Set the value at the path
|
||||||
arr.push(val);
|
arr.push(val);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,13 +48,18 @@ impl fmt::Display for Groups {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||||
pub struct Group {
|
pub struct Group(pub Idiom);
|
||||||
pub group: Idiom,
|
|
||||||
|
impl Deref for Group {
|
||||||
|
type Target = Idiom;
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Group {
|
impl fmt::Display for Group {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{}", self.group)
|
write!(f, "{}", self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,12 +73,7 @@ pub fn group(i: &str) -> IResult<&str, Groups> {
|
||||||
|
|
||||||
fn group_raw(i: &str) -> IResult<&str, Group> {
|
fn group_raw(i: &str) -> IResult<&str, Group> {
|
||||||
let (i, v) = basic(i)?;
|
let (i, v) = basic(i)?;
|
||||||
Ok((
|
Ok((i, Group(v)))
|
||||||
i,
|
|
||||||
Group {
|
|
||||||
group: v,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -88,12 +88,7 @@ mod tests {
|
||||||
let res = group(sql);
|
let res = group(sql);
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
let out = res.unwrap().1;
|
let out = res.unwrap().1;
|
||||||
assert_eq!(
|
assert_eq!(out, Groups(vec![Group(Idiom::parse("field"))]));
|
||||||
out,
|
|
||||||
Groups(vec![Group {
|
|
||||||
group: Idiom::parse("field")
|
|
||||||
}])
|
|
||||||
);
|
|
||||||
assert_eq!("GROUP BY field", format!("{}", out));
|
assert_eq!("GROUP BY field", format!("{}", out));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,12 +98,7 @@ mod tests {
|
||||||
let res = group(sql);
|
let res = group(sql);
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
let out = res.unwrap().1;
|
let out = res.unwrap().1;
|
||||||
assert_eq!(
|
assert_eq!(out, Groups(vec![Group(Idiom::parse("field"))]));
|
||||||
out,
|
|
||||||
Groups(vec![Group {
|
|
||||||
group: Idiom::parse("field")
|
|
||||||
}])
|
|
||||||
);
|
|
||||||
assert_eq!("GROUP BY field", format!("{}", out));
|
assert_eq!("GROUP BY field", format!("{}", out));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,14 +110,7 @@ mod tests {
|
||||||
let out = res.unwrap().1;
|
let out = res.unwrap().1;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
out,
|
out,
|
||||||
Groups(vec![
|
Groups(vec![Group(Idiom::parse("field")), Group(Idiom::parse("other.field"))])
|
||||||
Group {
|
|
||||||
group: Idiom::parse("field")
|
|
||||||
},
|
|
||||||
Group {
|
|
||||||
group: Idiom::parse("other.field")
|
|
||||||
},
|
|
||||||
])
|
|
||||||
);
|
);
|
||||||
assert_eq!("GROUP BY field, other.field", format!("{}", out));
|
assert_eq!("GROUP BY field, other.field", format!("{}", out));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue