MCPcopy Create free account
hub / github.com/erans/pgsqlite / json_contains

Function json_contains

src/functions/json_functions.rs:1528–1548  ·  view source on GitHub ↗

Check if container JSON contains the contained JSON

(container: &JsonValue, contained: &JsonValue)

Source from the content-addressed store, hash-verified

1526
1527/// Check if container JSON contains the contained JSON
1528fn json_contains(container: &JsonValue, contained: &JsonValue) -> bool {
1529 match (container, contained) {
1530 (JsonValue::Object(cont_map), JsonValue::Object(item_map)) => {
1531 // All keys in item must exist in container with same values
1532 item_map.iter().all(|(key, value)| {
1533 cont_map.get(key).is_some_and(|v| json_contains(v, value))
1534 })
1535 }
1536 (JsonValue::Array(cont_arr), JsonValue::Array(item_arr)) => {
1537 // All items in item_arr must be contained in cont_arr
1538 item_arr.iter().all(|item| {
1539 cont_arr.iter().any(|cont_item| json_contains(cont_item, item))
1540 })
1541 }
1542 (JsonValue::Array(cont_arr), item) => {
1543 // Check if array contains the single item
1544 cont_arr.iter().any(|cont_item| json_contains(cont_item, item))
1545 }
1546 _ => container == contained,
1547 }
1548}
1549
1550/// Register json_populate_record function
1551fn register_json_populate_record(conn: &Connection) -> Result<()> {

Callers 1

register_json_functionsFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected