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

Function first_select_expr

nodedb-sql/src/resolver/expr/tests.rs:12–25  ·  view source on GitHub ↗

Extract the first SELECT item expression from a simple `SELECT FROM `.

(sql: &str)

Source from the content-addressed store, hash-verified

10
11/// Extract the first SELECT item expression from a simple `SELECT <expr> FROM <tbl>`.
12fn first_select_expr(sql: &str) -> Expr {
13 let stmts = parse_sql(sql).expect("parse failed");
14 let Statement::Query(q) = &stmts[0] else {
15 panic!("expected query");
16 };
17 let sqlparser::ast::SetExpr::Select(sel) = q.body.as_ref() else {
18 panic!("expected select body");
19 };
20 match &sel.projection[0] {
21 SelectItem::UnnamedExpr(e) => e.clone(),
22 SelectItem::ExprWithAlias { expr, .. } => expr.clone(),
23 other => panic!("unexpected projection item: {other:?}"),
24 }
25}
26
27#[test]
28fn compound_identifier_two_parts_is_column() {

Calls 4

parse_sqlFunction · 0.50
expectMethod · 0.45
as_refMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected