mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 10:08:20 +00:00
Add jsonb to json_valid
This commit is contained in:
parent
dc6342c0de
commit
0b22fbd566
2 changed files with 10 additions and 12 deletions
|
@ -656,18 +656,16 @@ pub fn json_object(values: &[OwnedValue]) -> crate::Result<OwnedValue> {
|
|||
Ok(OwnedValue::Text(Text::json(result)))
|
||||
}
|
||||
|
||||
pub fn is_json_valid(json_value: &OwnedValue) -> crate::Result<OwnedValue> {
|
||||
match json_value {
|
||||
OwnedValue::Text(ref t) => match from_str::<Val>(t.as_str()) {
|
||||
Ok(_) => Ok(OwnedValue::Integer(1)),
|
||||
Err(_) => Ok(OwnedValue::Integer(0)),
|
||||
},
|
||||
OwnedValue::Blob(_) => {
|
||||
bail_parse_error!("Unsuported!")
|
||||
}
|
||||
OwnedValue::Null => Ok(OwnedValue::Null),
|
||||
_ => Ok(OwnedValue::Integer(1)),
|
||||
pub fn is_json_valid(json_value: &OwnedValue) -> OwnedValue {
|
||||
if matches!(json_value, OwnedValue::Null) {
|
||||
return OwnedValue::Null;
|
||||
}
|
||||
let json_is_ok = convert_dbtype_to_jsonb(json_value)
|
||||
.and_then(|_| {
|
||||
return Ok(OwnedValue::Integer(1));
|
||||
})
|
||||
.unwrap_or(OwnedValue::Integer(0));
|
||||
json_is_ok
|
||||
}
|
||||
|
||||
pub fn json_quote(value: &OwnedValue) -> crate::Result<OwnedValue> {
|
||||
|
|
|
@ -2216,7 +2216,7 @@ impl Program {
|
|||
}
|
||||
JsonFunc::JsonValid => {
|
||||
let json_value = &state.registers[*start_reg];
|
||||
state.registers[*dest] = is_json_valid(json_value)?;
|
||||
state.registers[*dest] = is_json_valid(json_value);
|
||||
}
|
||||
JsonFunc::JsonPatch => {
|
||||
assert_eq!(arg_count, 2);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue