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

Function register_array_length

src/functions/array_functions.rs:42–74  ·  view source on GitHub ↗

array_length(array, dimension) - Get length of array in specified dimension

(conn: &Connection)

Source from the content-addressed store, hash-verified

40
41/// array_length(array, dimension) - Get length of array in specified dimension
42fn register_array_length(conn: &Connection) -> Result<()> {
43 conn.create_scalar_function(
44 "array_length",
45 2,
46 FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
47 |ctx| {
48 let array_json: String = ctx.get(0)?;
49 let dimension: i32 = ctx.get(1)?;
50
51 match serde_json::from_str::<JsonValue>(&array_json) {
52 Ok(JsonValue::Array(arr)) => {
53 if dimension == 1 {
54 Ok(Some(arr.len() as i32))
55 } else {
56 // For higher dimensions, check first element
57 if let Some(JsonValue::Array(inner)) = arr.first() {
58 if dimension == 2 {
59 Ok(Some(inner.len() as i32))
60 } else {
61 Ok(None) // Higher dimensions not yet supported
62 }
63 } else {
64 Ok(None)
65 }
66 }
67 }
68 _ => Ok(None),
69 }
70 },
71 )?;
72
73 Ok(())
74}
75
76/// array_upper(array, dimension) - Get upper bound of array dimension
77fn register_array_upper(conn: &Connection) -> Result<()> {

Callers 1

register_array_functionsFunction · 0.85

Calls 2

getMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected