array_overlap(array1, array2) - Check if arrays have common elements
(conn: &Connection)
| 421 | |
| 422 | /// array_overlap(array1, array2) - Check if arrays have common elements |
| 423 | fn register_array_overlap(conn: &Connection) -> Result<()> { |
| 424 | conn.create_scalar_function( |
| 425 | "array_overlap", |
| 426 | 2, |
| 427 | FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC, |
| 428 | |ctx| { |
| 429 | let array1_json: String = ctx.get(0)?; |
| 430 | let array2_json: String = ctx.get(1)?; |
| 431 | |
| 432 | match ( |
| 433 | serde_json::from_str::<JsonValue>(&array1_json), |
| 434 | serde_json::from_str::<JsonValue>(&array2_json), |
| 435 | ) { |
| 436 | (Ok(JsonValue::Array(arr1)), Ok(JsonValue::Array(arr2))) => { |
| 437 | // Check if any element of arr1 is in arr2 |
| 438 | let has_overlap = arr1.iter().any(|elem| arr2.contains(elem)); |
| 439 | Ok(has_overlap) |
| 440 | } |
| 441 | _ => Ok(false), |
| 442 | } |
| 443 | }, |
| 444 | )?; |
| 445 | |
| 446 | Ok(()) |
| 447 | } |
| 448 | |
| 449 | /// array_slice(array, start, end) - Extract slice from array (1-based indexing) |
| 450 | fn register_array_slice(conn: &Connection) -> Result<()> { |
no test coverage detected