pub struct SchemaGraph { /* private fields */ }Expand description
A semantic graph of SurrealQL schema definitions.
Built from .surql files, provides fast lookups for tables, fields,
functions, and their relationships.
Implementations§
Source§impl SchemaGraph
impl SchemaGraph
Sourcepub fn from_source(input: &str) -> Result<Self>
pub fn from_source(input: &str) -> Result<Self>
Build a schema graph from a SurrealQL string.
Sourcepub fn from_files(dir: &Path) -> Result<Self>
pub fn from_files(dir: &Path) -> Result<Self>
Build a schema graph by walking all .surql files in a directory.
Source locations are tracked per file for go-to-definition support.
Sourcepub fn from_files_per_file(dir: &Path) -> Result<HashMap<PathBuf, Self>>
pub fn from_files_per_file(dir: &Path) -> Result<HashMap<PathBuf, Self>>
Build per-file schema graphs by walking all .surql files in a directory.
Returns a map from file path to its individual SchemaGraph.
Used for incremental rebuilding: on save, only the changed file is re-parsed,
then all per-file graphs are merged.
Sourcepub fn from_single_file(path: &Path) -> Option<Self>
pub fn from_single_file(path: &Path) -> Option<Self>
Build a schema graph from a single .surql file.
Returns None if the file cannot be read or parsed.
Sourcepub fn attach_source_locations(&mut self, source: &str, file: &Path)
pub fn attach_source_locations(&mut self, source: &str, file: &Path)
Scan source text via the lexer for DEFINE statement positions.
Sourcepub fn merge(&mut self, other: SchemaGraph)
pub fn merge(&mut self, other: SchemaGraph)
Merge another schema graph into this one.
Fields, indexes, and events are deduplicated by name. SCHEMAFULL wins over SCHEMALESS (once a table is marked SCHEMAFULL, it stays).
pub fn from_definitions(defs: &SchemaDefinitions) -> Self
Sourcepub fn scoped(&self, ns: Option<&str>, db: Option<&str>) -> Self
pub fn scoped(&self, ns: Option<&str>, db: Option<&str>) -> Self
Return a filtered schema containing only tables matching the given NS/DB scope. Tables with no NS/DB (None) are included in all scopes (default context).
Sourcepub fn table_names(&self) -> impl Iterator<Item = &str>
pub fn table_names(&self) -> impl Iterator<Item = &str>
Iterate over all table names in the schema.
Sourcepub fn indexes_of(&self, table: &str) -> &[IndexDef]
pub fn indexes_of(&self, table: &str) -> &[IndexDef]
Indexes defined on a table.
Sourcepub fn function(&self, name: &str) -> Option<&FunctionDef>
pub fn function(&self, name: &str) -> Option<&FunctionDef>
Get function definition by name (without the fn:: prefix).
Sourcepub fn function_names(&self) -> impl Iterator<Item = &str>
pub fn function_names(&self) -> impl Iterator<Item = &str>
Iterate over all function names (without fn:: prefix).
Sourcepub fn param_names(&self) -> impl Iterator<Item = &str>
pub fn param_names(&self) -> impl Iterator<Item = &str>
Iterate over all defined param names.
Sourcepub fn find_field(&self, field_name: &str) -> Vec<(&str, &FieldDef)>
pub fn find_field(&self, field_name: &str) -> Vec<(&str, &FieldDef)>
Find a field by name across all tables. Returns (table_name, field_def).
Uses a pre-built HashMap index for O(1) lookup by field name, instead of scanning all tables.
Sourcepub fn field_on(&self, table: &str, field_name: &str) -> Option<&FieldDef>
pub fn field_on(&self, table: &str, field_name: &str) -> Option<&FieldDef>
Find a field on a specific table.
Sourcepub fn tables_reachable_from(
&self,
start: &str,
max_depth: usize,
) -> Vec<(String, usize, Vec<String>)>
pub fn tables_reachable_from( &self, start: &str, max_depth: usize, ) -> Vec<(String, usize, Vec<String>)>
Tables reachable from start within max_depth hops via record<> links.
Uses BFS with cycle detection. Returns (table_name, depth, path) where
path is the chain of table.field segments traversed to reach each table.
The starting table itself is not included in the results.
Sourcepub fn tables_referencing(&self, target: &str) -> Vec<(String, String)>
pub fn tables_referencing(&self, target: &str) -> Vec<(String, String)>
Tables that reference target via record<target> fields (reverse dependencies).
Returns (referencing_table, field_name) pairs. Useful for answering:
“What would break if I drop or rename this table?”
Sourcepub fn siblings_of(&self, table: &str) -> Vec<(String, String, String)>
pub fn siblings_of(&self, table: &str) -> Vec<(String, String, String)>
Tables that share a common record<> target with table (siblings).
Answers: “Which other tables also link to the same targets as this table?”
Returns (sibling_table, shared_target, via_field) triples.
Sourcepub fn dependency_tree(&self, root: &str, max_depth: usize) -> DependencyNode
pub fn dependency_tree(&self, root: &str, max_depth: usize) -> DependencyNode
Build a full dependency tree rooted at root, following record<> links.
Cycles are detected: if a table appears as its own ancestor, the node
is marked with is_cycle = true and has no children (the recursion stops).
A max_nodes safety cap (1000) prevents exponential blowup on diamond-shaped
graphs where the same table is reachable through many paths.
Sourcepub fn build_graph_tree_markdown(&self) -> String
pub fn build_graph_tree_markdown(&self) -> String
Generate a markdown graph tree for all tables in the schema.
Builds a dependency tree for each table and formats it as an
indented markdown tree view. Used by the LSP to cache graph.md.
Sourcepub fn build_docs_markdown(&self) -> String
pub fn build_docs_markdown(&self) -> String
Generate markdown documentation from schema definitions.
Includes tables with fields (type, default, comment), indexes, events, and function signatures with parameters and return types.
Trait Implementations§
Source§impl Clone for SchemaGraph
impl Clone for SchemaGraph
Source§fn clone(&self) -> SchemaGraph
fn clone(&self) -> SchemaGraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SchemaGraph
impl Debug for SchemaGraph
Source§impl Default for SchemaGraph
impl Default for SchemaGraph
Source§fn default() -> SchemaGraph
fn default() -> SchemaGraph
Auto Trait Implementations§
impl Freeze for SchemaGraph
impl RefUnwindSafe for SchemaGraph
impl Send for SchemaGraph
impl Sync for SchemaGraph
impl Unpin for SchemaGraph
impl UnsafeUnpin for SchemaGraph
impl UnwindSafe for SchemaGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more