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

Function parse_object_name

nodedb-sql/src/parser/normalize.rs:74–87  ·  view source on GitHub ↗
(sql: &str)

Source from the content-addressed store, hash-verified

72 use sqlparser::ast::Statement;
73
74 fn parse_object_name(sql: &str) -> sqlparser::ast::ObjectName {
75 // Parse a `SELECT * FROM <name>` and extract the table ObjectName.
76 let stmts = parse_sql(sql).expect("parse failed");
77 let Statement::Query(q) = &stmts[0] else {
78 panic!("expected query");
79 };
80 let sqlparser::ast::SetExpr::Select(sel) = q.body.as_ref() else {
81 panic!("expected select body");
82 };
83 match &sel.from[0].relation {
84 sqlparser::ast::TableFactor::Table { name, .. } => name.clone(),
85 other => panic!("expected table factor, got {other:?}"),
86 }
87 }
88
89 #[test]
90 fn plain_name_accepted() {

Callers 2

plain_name_acceptedFunction · 0.85

Calls 4

parse_sqlFunction · 0.70
expectMethod · 0.45
as_refMethod · 0.45
cloneMethod · 0.45

Tested by 2

plain_name_acceptedFunction · 0.68