pub struct SchemaGraph {
pub graph: DiGraph<SchemaNode, SchemaEdge>,
pub table_index: HashMap<String, NodeIndex>,
pub column_index: HashMap<String, NodeIndex>,
pub index_index: HashMap<String, NodeIndex>,
}Fields§
§graph: DiGraph<SchemaNode, SchemaEdge>§table_index: HashMap<String, NodeIndex>table_name -> NodeIndex
column_index: HashMap<String, NodeIndex>“table.column” -> NodeIndex
index_index: HashMap<String, NodeIndex>index_name -> NodeIndex
Implementations§
Source§impl SchemaGraph
impl SchemaGraph
pub fn new() -> Self
pub fn add_table( &mut self, name: &str, estimated_rows: Option<u64>, ) -> NodeIndex
pub fn add_column( &mut self, table: &str, name: &str, data_type: &str, nullable: bool, ) -> NodeIndex
pub fn add_index( &mut self, index_name: &str, table: &str, unique: bool, ) -> NodeIndex
pub fn add_foreign_key( &mut self, from_table: &str, to_table: &str, constraint_name: Option<String>, from_columns: Vec<String>, to_columns: Vec<String>, cascade_delete: bool, cascade_update: bool, )
Sourcepub fn tables_referencing(&self, table: &str) -> Vec<String>
pub fn tables_referencing(&self, table: &str) -> Vec<String>
Returns all tables that hold a foreign key pointing TO the given table.
Sourcepub fn fk_downstream(&self, table: &str) -> Vec<String>
pub fn fk_downstream(&self, table: &str) -> Vec<String>
Depth-first search: all tables reachable from table via FK edges.
Sourcepub fn all_tables(&self) -> Vec<String>
pub fn all_tables(&self) -> Vec<String>
List all tables in the graph.
Sourcepub fn text_summary(&self) -> String
pub fn text_summary(&self) -> String
Produces a plain-text adjacency summary of the graph.
Sourcepub fn export_mermaid(&self) -> String
pub fn export_mermaid(&self) -> String
Export the schema as a Mermaid ER diagram.
Output can be embedded in a Markdown file and rendered by GitHub, GitLab, Notion, etc.
Example:
erDiagram
users {
uuid id PK
text email
}
orders ||--o{ users : "user_id"Sourcepub fn export_graphviz(&self) -> String
pub fn export_graphviz(&self) -> String
Export the schema as a Graphviz DOT document.
Pipe to dot -Tsvg -o schema.svg or dot -Tpng -o schema.png.
Trait Implementations§
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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