MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / expr_to_sql_value

Function expr_to_sql_value

nodedb-sql/src/planner/dml_helpers.rs:28–54  ·  view source on GitHub ↗
(expr: &ast::Expr)

Source from the content-addressed store, hash-verified

26}
27
28pub(super) fn expr_to_sql_value(expr: &ast::Expr) -> Result<SqlValue> {
29 match expr {
30 ast::Expr::Value(v) => convert_value(&v.value),
31 // Array literals lower element-wise into `SqlValue::Array`; there is
32 // no array-literal `SqlValue` the constant folder could produce.
33 ast::Expr::Array(ast::Array { elem, .. }) => {
34 let vals = elem.iter().map(expr_to_sql_value).collect::<Result<_>>()?;
35 Ok(SqlValue::Array(vals))
36 }
37 // `ST_Point(...)` / `ST_GeomFromGeoJSON(...)` synthesise a GeoJSON
38 // string in place rather than resolving as registered scalar
39 // functions, so they keep their bespoke handling.
40 ast::Expr::Function(func) => match SpatialConstructor::from_function(func) {
41 Some(ctor) => spatial_constructor_to_value(ctor, func),
42 // Non-spatial functions (`now()`, `date_add(...)`, registered
43 // scalars) fold through the shared pipeline below.
44 None => fold_constant_value(expr),
45 },
46 // Everything else — `::TYPE` / `CAST(... AS TYPE)` casts, arithmetic,
47 // string concatenation, parenthesised literals — goes through the
48 // same resolver and constant folder the `SELECT` projection path
49 // uses, so the two surfaces never drift. Only genuinely row- or
50 // runtime-dependent expressions (column refs, subqueries, unknown
51 // functions) fail here.
52 _ => fold_constant_value(expr),
53 }
54}
55
56fn fold_constant_value(expr: &ast::Expr) -> Result<SqlValue> {
57 let sql_expr = crate::resolver::expr::convert_expr(expr)?;

Callers 3

convert_value_rowsFunction · 0.85
collect_pk_equalitiesFunction · 0.85
build_kv_insert_planFunction · 0.85

Calls 4

convert_valueFunction · 0.85
fold_constant_valueFunction · 0.85
iterMethod · 0.45

Tested by

no test coverage detected