diff --git a/lib/src/dbs/executor.rs b/lib/src/dbs/executor.rs index b59aa03b..3a454d35 100644 --- a/lib/src/dbs/executor.rs +++ b/lib/src/dbs/executor.rs @@ -142,7 +142,7 @@ impl<'a> Executor<'a> { // Allowed to run? opt.check(Level::Db)?; // Process the option - match &stm.name.name.to_uppercase()[..] { + match &stm.name.to_uppercase()[..] { "FIELDS" => opt = opt.fields(stm.what), "EVENTS" => opt = opt.events(stm.what), "TABLES" => opt = opt.tables(stm.what), diff --git a/lib/src/sql/ident.rs b/lib/src/sql/ident.rs index 6bf6a9d6..bef33310 100644 --- a/lib/src/sql/ident.rs +++ b/lib/src/sql/ident.rs @@ -8,40 +8,40 @@ use nom::character::complete::char; use nom::sequence::delimited; use serde::{Deserialize, Serialize}; use std::fmt; +use std::ops::Deref; use std::str; -#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize)] -pub struct Ident { - pub name: String, -} +#[derive(Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize)] +pub struct Ident(pub String); impl From for Ident { fn from(s: String) -> Self { - Ident { - name: s, - } + Ident(s) } } impl<'a> From<&'a str> for Ident { fn from(i: &str) -> Ident { - Ident { - name: String::from(i), - } + Ident(String::from(i)) } } impl<'a> From<&'a String> for Ident { fn from(i: &String) -> Ident { - Ident { - name: String::from(i), - } + Ident(String::from(i)) + } +} + +impl Deref for Ident { + type Target = String; + fn deref(&self) -> &Self::Target { + &self.0 } } impl fmt::Display for Ident { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", escape(&self.name, &val_char, "`")) + write!(f, "{}", escape(&self.0, &val_char, "`")) } } diff --git a/lib/src/sql/param.rs b/lib/src/sql/param.rs index 21c58e45..7cefd639 100644 --- a/lib/src/sql/param.rs +++ b/lib/src/sql/param.rs @@ -41,7 +41,7 @@ impl Param { // Find a base variable by name match self.parts.first() { // The first part will be a field - Some(Part::Field(v)) => match &v.name[..] { + Some(Part::Field(v)) => match v.as_str() { "this" => match doc { // The base document exists Some(v) => { @@ -55,7 +55,7 @@ impl Param { // The base document does not exist None => Ok(Value::None), }, - _ => match ctx.value::(&v.name) { + _ => match ctx.value::(v) { // The base variable exists Some(v) => { // Get the path parts diff --git a/lib/src/sql/value/compare.rs b/lib/src/sql/value/compare.rs index dd39dbe6..bf1eb562 100644 --- a/lib/src/sql/value/compare.rs +++ b/lib/src/sql/value/compare.rs @@ -16,7 +16,7 @@ impl Value { Some(p) => match (self, other) { // Current path part is an object (Value::Object(a), Value::Object(b)) => match p { - Part::Field(f) => match (a.get(&f.name), b.get(&f.name)) { + Part::Field(f) => match (a.get(f as &str), b.get(f as &str)) { (Some(a), Some(b)) => a.compare(b, path.next(), collate, numeric), (Some(_), None) => Some(Ordering::Greater), (None, Some(_)) => Some(Ordering::Less), diff --git a/lib/src/sql/value/del.rs b/lib/src/sql/value/del.rs index 4d1923b3..45e0edab 100644 --- a/lib/src/sql/value/del.rs +++ b/lib/src/sql/value/del.rs @@ -27,10 +27,10 @@ impl Value { Value::Object(v) => match p { Part::Field(f) => match path.len() { 1 => { - v.remove(&f.name); + v.remove(f as &str); Ok(()) } - _ => match v.get_mut(&f.name) { + _ => match v.get_mut(f as &str) { Some(v) if v.is_some() => v.del(ctx, opt, txn, path.next()).await, _ => Ok(()), }, diff --git a/lib/src/sql/value/each.rs b/lib/src/sql/value/each.rs index f1de2151..880cc56a 100644 --- a/lib/src/sql/value/each.rs +++ b/lib/src/sql/value/each.rs @@ -13,7 +13,7 @@ impl Value { Some(p) => match self { // Current path part is an object Value::Object(v) => match p { - Part::Field(f) => match v.get(&f.name) { + Part::Field(f) => match v.get(f as &str) { Some(v) => v._each(path.next(), prev.push(p.clone())), None => vec![], }, diff --git a/lib/src/sql/value/get.rs b/lib/src/sql/value/get.rs index 1520ed25..34124c27 100644 --- a/lib/src/sql/value/get.rs +++ b/lib/src/sql/value/get.rs @@ -26,7 +26,7 @@ impl Value { Some(p) => match self { // Current path part is an object Value::Object(v) => match p { - Part::Field(f) => match v.get(&f.name) { + Part::Field(f) => match v.get(f as &str) { Some(v) => v.get(ctx, opt, txn, path.next()).await, None => Ok(Value::None), }, diff --git a/lib/src/sql/value/pick.rs b/lib/src/sql/value/pick.rs index 8253f3b9..2240c9a1 100644 --- a/lib/src/sql/value/pick.rs +++ b/lib/src/sql/value/pick.rs @@ -9,7 +9,7 @@ impl Value { Some(p) => match self { // Current path part is an object Value::Object(v) => match p { - Part::Field(f) => match v.get(&f.name) { + Part::Field(f) => match v.get(f as &str) { Some(v) => v.pick(path.next()), None => Value::None, }, diff --git a/lib/src/sql/value/set.rs b/lib/src/sql/value/set.rs index 986149e3..d821c6d5 100644 --- a/lib/src/sql/value/set.rs +++ b/lib/src/sql/value/set.rs @@ -24,12 +24,12 @@ impl Value { Some(p) => match self { // Current path part is an object Value::Object(v) => match p { - Part::Field(f) => match v.get_mut(&f.name) { + Part::Field(f) => match v.get_mut(f as &str) { Some(v) if v.is_some() => v.set(ctx, opt, txn, path.next(), val).await, _ => { let mut obj = Value::base(); obj.set(ctx, opt, txn, path.next(), val).await?; - v.insert(f.name.to_owned(), obj); + v.insert(f.to_string(), obj); Ok(()) } },