mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
clippy
This commit is contained in:
parent
7710081796
commit
479dd9c35a
3 changed files with 35 additions and 39 deletions
|
@ -167,7 +167,7 @@ pub fn json_remove(args: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
|||
|
||||
let el_type = json.is_valid()?;
|
||||
|
||||
json_string_to_db_type(json, el_type, OutputVariant::AsString)
|
||||
json_string_to_db_type(json, el_type, OutputVariant::String)
|
||||
}
|
||||
|
||||
pub fn jsonb_remove(args: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
||||
|
@ -206,7 +206,7 @@ pub fn json_replace(args: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
|||
|
||||
let el_type = json.is_valid()?;
|
||||
|
||||
json_string_to_db_type(json, el_type, super::OutputVariant::AsString)
|
||||
json_string_to_db_type(json, el_type, super::OutputVariant::String)
|
||||
}
|
||||
|
||||
pub fn jsonb_replace(args: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
||||
|
@ -228,7 +228,7 @@ pub fn jsonb_replace(args: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
|||
|
||||
let el_type = json.is_valid()?;
|
||||
|
||||
json_string_to_db_type(json, el_type, OutputVariant::AsBinary)
|
||||
json_string_to_db_type(json, el_type, OutputVariant::Binary)
|
||||
}
|
||||
|
||||
pub fn json_insert(args: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
||||
|
@ -250,7 +250,7 @@ pub fn json_insert(args: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
|||
|
||||
let el_type = json.is_valid()?;
|
||||
|
||||
json_string_to_db_type(json, el_type, OutputVariant::AsString)
|
||||
json_string_to_db_type(json, el_type, OutputVariant::String)
|
||||
}
|
||||
|
||||
pub fn jsonb_insert(args: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
||||
|
@ -272,7 +272,7 @@ pub fn jsonb_insert(args: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
|||
|
||||
let el_type = json.is_valid()?;
|
||||
|
||||
json_string_to_db_type(json, el_type, OutputVariant::AsBinary)
|
||||
json_string_to_db_type(json, el_type, OutputVariant::Binary)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -414,25 +414,21 @@ impl PathOperation for DeleteOperation {
|
|||
0
|
||||
};
|
||||
json.update_parent_references(stack, target.delta + delta + h_delta)?;
|
||||
} else if let JsonLocationKind::ObjectProperty(key_idx) = target.field_key_index {
|
||||
let value_idx = target.field_value_index;
|
||||
let (JsonbHeader(_, value_size), value_header_size) = json.read_header(value_idx)?;
|
||||
let (JsonbHeader(_, key_size), key_header_size) = json.read_header(key_idx)?;
|
||||
let delta = 0 - (value_header_size + value_size + key_size + key_header_size) as isize;
|
||||
|
||||
let end_pos = key_idx + value_header_size + value_size + key_size + key_header_size;
|
||||
json.data.drain(key_idx..end_pos);
|
||||
|
||||
json.update_parent_references(stack, delta + target.delta)?;
|
||||
} else {
|
||||
if let JsonLocationKind::ObjectProperty(key_idx) = target.field_key_index {
|
||||
let value_idx = target.field_value_index;
|
||||
let (JsonbHeader(_, value_size), value_header_size) =
|
||||
json.read_header(value_idx)?;
|
||||
let (JsonbHeader(_, key_size), key_header_size) = json.read_header(key_idx)?;
|
||||
let delta =
|
||||
0 - (value_header_size + value_size + key_size + key_header_size) as isize;
|
||||
|
||||
let end_pos = key_idx + value_header_size + value_size + key_size + key_header_size;
|
||||
json.data.drain(key_idx..end_pos);
|
||||
|
||||
json.update_parent_references(stack, delta + target.delta)?;
|
||||
} else {
|
||||
let nul = JsonbHeader::make_null().into_bytes();
|
||||
let nul_bytes = nul.as_bytes();
|
||||
json.data.clear();
|
||||
json.data.extend_from_slice(nul_bytes);
|
||||
}
|
||||
let nul = JsonbHeader::make_null().into_bytes();
|
||||
let nul_bytes = nul.as_bytes();
|
||||
json.data.clear();
|
||||
json.data.extend_from_slice(nul_bytes);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -1302,7 +1298,7 @@ impl Jsonb {
|
|||
b'"' | b'\'' => {
|
||||
pos = self.deserialize_string(input, pos)?;
|
||||
}
|
||||
c if (b'0'..=b'9').contains(&c)
|
||||
c if c.is_ascii_digit()
|
||||
|| c == b'-'
|
||||
|| c == b'+'
|
||||
|| c == b'.'
|
||||
|
@ -1987,7 +1983,7 @@ impl Jsonb {
|
|||
Ok(stack)
|
||||
}
|
||||
|
||||
pub fn operate_on_path<'a, T>(&mut self, path: &JsonPath, operation: &'a mut T) -> Result<()>
|
||||
pub fn operate_on_path<T>(&mut self, path: &JsonPath, operation: &mut T) -> Result<()>
|
||||
where
|
||||
T: PathOperation,
|
||||
{
|
||||
|
@ -2501,7 +2497,7 @@ impl Jsonb {
|
|||
}
|
||||
};
|
||||
|
||||
return Err(LimboError::ParseError("Not found".to_string()));
|
||||
Err(LimboError::ParseError("Not found".to_string()))
|
||||
}
|
||||
|
||||
fn skip_element(&self, mut pos: usize) -> Result<usize> {
|
||||
|
|
|
@ -43,9 +43,9 @@ enum Conv {
|
|||
}
|
||||
|
||||
enum OutputVariant {
|
||||
AsElementType,
|
||||
AsBinary,
|
||||
AsString,
|
||||
ElementType,
|
||||
Binary,
|
||||
String,
|
||||
}
|
||||
|
||||
pub fn get_json(json_value: &OwnedValue, indent: Option<&str>) -> crate::Result<OwnedValue> {
|
||||
|
@ -170,7 +170,7 @@ pub fn json_array(values: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
|||
}
|
||||
json.finalize_unsafe(ElementType::ARRAY)?;
|
||||
|
||||
json_string_to_db_type(json, ElementType::ARRAY, OutputVariant::AsElementType)
|
||||
json_string_to_db_type(json, ElementType::ARRAY, OutputVariant::ElementType)
|
||||
}
|
||||
|
||||
pub fn jsonb_array(values: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
||||
|
@ -185,7 +185,7 @@ pub fn jsonb_array(values: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
|||
}
|
||||
json.finalize_unsafe(ElementType::ARRAY)?;
|
||||
|
||||
json_string_to_db_type(json, ElementType::ARRAY, OutputVariant::AsBinary)
|
||||
json_string_to_db_type(json, ElementType::ARRAY, OutputVariant::Binary)
|
||||
}
|
||||
|
||||
pub fn json_array_length(
|
||||
|
@ -231,7 +231,7 @@ pub fn json_set(args: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
|||
|
||||
let el_type = json.is_valid()?;
|
||||
|
||||
json_string_to_db_type(json, el_type, OutputVariant::AsString)
|
||||
json_string_to_db_type(json, el_type, OutputVariant::String)
|
||||
}
|
||||
|
||||
/// Implements the -> operator. Always returns a proper JSON value.
|
||||
|
@ -279,7 +279,7 @@ pub fn json_arrow_shift_extract(
|
|||
Ok(json_string_to_db_type(
|
||||
extracted,
|
||||
element_type,
|
||||
OutputVariant::AsElementType,
|
||||
OutputVariant::ElementType,
|
||||
)?)
|
||||
} else {
|
||||
Ok(OwnedValue::Null)
|
||||
|
@ -302,7 +302,7 @@ pub fn json_extract(value: &OwnedValue, paths: &[OwnedValue]) -> crate::Result<O
|
|||
}
|
||||
let (json, element_type) = jsonb_extract_internal(value, paths)?;
|
||||
|
||||
let result = json_string_to_db_type(json, element_type, OutputVariant::AsElementType)?;
|
||||
let result = json_string_to_db_type(json, element_type, OutputVariant::ElementType)?;
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ pub fn jsonb_extract(value: &OwnedValue, paths: &[OwnedValue]) -> crate::Result<
|
|||
}
|
||||
|
||||
let (json, element_type) = jsonb_extract_internal(value, paths)?;
|
||||
let result = json_string_to_db_type(json, element_type, OutputVariant::AsElementType)?;
|
||||
let result = json_string_to_db_type(json, element_type, OutputVariant::ElementType)?;
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
@ -377,13 +377,13 @@ fn json_string_to_db_type(
|
|||
flag: OutputVariant,
|
||||
) -> crate::Result<OwnedValue> {
|
||||
let mut json_string = json.to_string()?;
|
||||
if matches!(flag, OutputVariant::AsBinary) {
|
||||
if matches!(flag, OutputVariant::Binary) {
|
||||
return Ok(OwnedValue::Blob(Rc::new(json.data())));
|
||||
}
|
||||
match element_type {
|
||||
ElementType::ARRAY | ElementType::OBJECT => Ok(OwnedValue::Text(Text::json(json_string))),
|
||||
ElementType::TEXT | ElementType::TEXT5 | ElementType::TEXTJ | ElementType::TEXTRAW => {
|
||||
if matches!(flag, OutputVariant::AsElementType) {
|
||||
if matches!(flag, OutputVariant::ElementType) {
|
||||
json_string.remove(json_string.len() - 1);
|
||||
json_string.remove(0);
|
||||
Ok(OwnedValue::Text(Text {
|
||||
|
@ -568,7 +568,7 @@ pub fn json_object(values: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
|||
|
||||
json.finalize_unsafe(ElementType::OBJECT)?;
|
||||
|
||||
json_string_to_db_type(json, ElementType::OBJECT, OutputVariant::AsString)
|
||||
json_string_to_db_type(json, ElementType::OBJECT, OutputVariant::String)
|
||||
}
|
||||
|
||||
pub fn jsonb_object(values: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
||||
|
@ -589,7 +589,7 @@ pub fn jsonb_object(values: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
|||
|
||||
json.finalize_unsafe(ElementType::OBJECT)?;
|
||||
|
||||
json_string_to_db_type(json, ElementType::OBJECT, OutputVariant::AsBinary)
|
||||
json_string_to_db_type(json, ElementType::OBJECT, OutputVariant::Binary)
|
||||
}
|
||||
|
||||
pub fn is_json_valid(json_value: &OwnedValue) -> OwnedValue {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue