MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / collect_sql_relation_usages

Function collect_sql_relation_usages

internal/cbm/extract_defs.c:7261–7278  ·  view source on GitHub ↗

Collect FROM/JOIN table references (tree-sitter-sql `relation` nodes) anywhere under `node` and emit them as usages scoped to enclosing_qn. pass_usages then resolves each ref_name to the referenced Table/View def and creates a USAGE lineage edge (e.g. a view -> the tables it selects from). Emitting them here (rather than via the generic identifier walker) sets the correct enclosing scope and bypas

Source from the content-addressed store, hash-verified

7259// (rather than via the generic identifier walker) sets the correct enclosing
7260// scope and bypasses the is_definition_name suppression that drops them.
7261static void collect_sql_relation_usages(CBMExtractCtx *ctx, TSNode node, const char *enclosing_qn) {
7262 if (strcmp(ts_node_type(node), "relation") == 0) {
7263 TSNode nm = resolve_sql_func_name(node); // object_reference -> identifier
7264 if (!ts_node_is_null(nm)) {
7265 char *tname = cbm_node_text(ctx->arena, nm, ctx->source);
7266 if (tname && tname[0]) {
7267 CBMUsage usage = {0};
7268 usage.ref_name = tname;
7269 usage.enclosing_func_qn = enclosing_qn;
7270 cbm_usages_push(&ctx->result->usages, ctx->arena, usage);
7271 }
7272 }
7273 }
7274 uint32_t n = ts_node_child_count(node);
7275 for (uint32_t i = 0; i < n; i++) {
7276 collect_sql_relation_usages(ctx, ts_node_child(node, i), enclosing_qn);
7277 }
7278}
7279
7280// Handle SQL DDL relation defs: CREATE TABLE / VIEW / MATERIALIZED VIEW become
7281// first-class Table/View nodes rather than generic Variable nodes. The relation

Callers 1

Calls 3

resolve_sql_func_nameFunction · 0.85
cbm_node_textFunction · 0.85
cbm_usages_pushFunction · 0.85

Tested by

no test coverage detected