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

Function register_array_contains

src/functions/array_functions.rs:369–393  ·  view source on GitHub ↗

array_contains(array1, array2) - Check if array1 contains all elements of array2

(conn: &Connection)

Source from the content-addressed store, hash-verified

367
368/// array_contains(array1, array2) - Check if array1 contains all elements of array2
369fn register_array_contains(conn: &Connection) -> Result<()> {
370 conn.create_scalar_function(
371 "array_contains",
372 2,
373 FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
374 |ctx| {
375 let array1_json: String = ctx.get(0)?;
376 let array2_json: String = ctx.get(1)?;
377
378 match (
379 serde_json::from_str::<JsonValue>(&array1_json),
380 serde_json::from_str::<JsonValue>(&array2_json),
381 ) {
382 (Ok(JsonValue::Array(arr1)), Ok(JsonValue::Array(arr2))) => {
383 // Check if all elements of arr2 are in arr1
384 let contains_all = arr2.iter().all(|elem| arr1.contains(elem));
385 Ok(contains_all)
386 }
387 _ => Ok(false),
388 }
389 },
390 )?;
391
392 Ok(())
393}
394
395/// array_contained(array1, array2) - Check if all elements of array1 are in array2
396fn register_array_contained(conn: &Connection) -> Result<()> {

Callers 1

register_array_functionsFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected