Add functions on SQL Value for matching on type
This commit is contained in:
parent
410295c800
commit
8dc7341cb1
1 changed files with 37 additions and 0 deletions
|
@ -510,6 +510,26 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_uuid(&self) -> bool {
|
||||||
|
matches!(self, Value::Uuid(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_thing(&self) -> bool {
|
||||||
|
matches!(self, Value::Thing(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_strand(&self) -> bool {
|
||||||
|
matches!(self, Value::Strand(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_array(&self) -> bool {
|
||||||
|
matches!(self, Value::Array(_))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_object(&self) -> bool {
|
||||||
|
matches!(self, Value::Object(_))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_type_record(&self, types: &[Table]) -> bool {
|
pub fn is_type_record(&self, types: &[Table]) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Value::Thing(v) => types.iter().any(|tb| tb.0 == v.tb),
|
Value::Thing(v) => types.iter().any(|tb| tb.0 == v.tb),
|
||||||
|
@ -736,6 +756,23 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn make_table(self) -> Value {
|
||||||
|
match self {
|
||||||
|
Value::Table(_) => self,
|
||||||
|
Value::Strand(v) => Value::Table(Table(v.0)),
|
||||||
|
_ => Value::Table(Table(self.as_strand().0)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn make_table_or_thing(self) -> Value {
|
||||||
|
match self {
|
||||||
|
Value::Table(_) => self,
|
||||||
|
Value::Thing(_) => self,
|
||||||
|
Value::Strand(v) => Value::Table(Table(v.0)),
|
||||||
|
_ => Value::Table(Table(self.as_strand().0)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn convert_to(self, kind: &Kind) -> Value {
|
pub fn convert_to(self, kind: &Kind) -> Value {
|
||||||
match kind {
|
match kind {
|
||||||
Kind::Any => self,
|
Kind::Any => self,
|
||||||
|
|
Loading…
Reference in a new issue