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

Function register_array_contained

src/functions/array_functions.rs:396–420  ·  view source on GitHub ↗

array_contained(array1, array2) - Check if all elements of array1 are in array2

(conn: &Connection)

Source from the content-addressed store, hash-verified

394
395/// array_contained(array1, array2) - Check if all elements of array1 are in array2
396fn register_array_contained(conn: &Connection) -> Result<()> {
397 conn.create_scalar_function(
398 "array_contained",
399 2,
400 FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
401 |ctx| {
402 let array1_json: String = ctx.get(0)?;
403 let array2_json: String = ctx.get(1)?;
404
405 match (
406 serde_json::from_str::<JsonValue>(&array1_json),
407 serde_json::from_str::<JsonValue>(&array2_json),
408 ) {
409 (Ok(JsonValue::Array(arr1)), Ok(JsonValue::Array(arr2))) => {
410 // Check if all elements of arr1 are in arr2
411 let contained_all = arr1.iter().all(|elem| arr2.contains(elem));
412 Ok(contained_all)
413 }
414 _ => Ok(false),
415 }
416 },
417 )?;
418
419 Ok(())
420}
421
422/// array_overlap(array1, array2) - Check if arrays have common elements
423fn register_array_overlap(conn: &Connection) -> Result<()> {

Callers 1

register_array_functionsFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected