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

Function register_array_cat

src/functions/array_functions.rs:242–265  ·  view source on GitHub ↗

array_cat(array1, array2) - Concatenate two arrays

(conn: &Connection)

Source from the content-addressed store, hash-verified

240
241/// array_cat(array1, array2) - Concatenate two arrays
242fn register_array_cat(conn: &Connection) -> Result<()> {
243 conn.create_scalar_function(
244 "array_cat",
245 2,
246 FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
247 |ctx| {
248 let array1_json: String = ctx.get(0)?;
249 let array2_json: String = ctx.get(1)?;
250
251 match (
252 serde_json::from_str::<JsonValue>(&array1_json),
253 serde_json::from_str::<JsonValue>(&array2_json),
254 ) {
255 (Ok(JsonValue::Array(mut arr1)), Ok(JsonValue::Array(arr2))) => {
256 arr1.extend(arr2);
257 Ok(serde_json::to_string(&arr1).ok())
258 }
259 _ => Ok(None),
260 }
261 },
262 )?;
263
264 Ok(())
265}
266
267/// array_remove(array, element) - Remove all occurrences of element
268fn register_array_remove(conn: &Connection) -> Result<()> {

Callers 1

register_array_functionsFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected