SchemaGraph

Struct SchemaGraph 

Source
pub struct SchemaGraph {
    pub schema: Schema,
    pub parents: Vec<Vec<TableId>>,
    pub children: Vec<Vec<TableId>>,
}
Expand description

Schema dependency graph built from foreign key relationships.

The graph represents parent → child relationships where:

  • A parent is a table referenced by another table’s FK
  • A child is a table that has an FK referencing another table

This ordering allows processing parents before children, ensuring that when sampling/filtering children, parent data is already available.

Fields§

§schema: Schema

The underlying schema

§parents: Vec<Vec<TableId>>

For each table, list of parent tables (tables this table references via FK)

§children: Vec<Vec<TableId>>

For each table, list of child tables (tables that reference this table via FK)

Implementations§

Source§

impl SchemaGraph

Source

pub fn from_schema(schema: Schema) -> Self

Build a dependency graph from a schema

Source

pub fn len(&self) -> usize

Get the number of tables in the graph

Source

pub fn is_empty(&self) -> bool

Check if the graph is empty

Source

pub fn table_name(&self, id: TableId) -> Option<&str>

Get the table name for a table ID

Source

pub fn has_self_reference(&self, id: TableId) -> bool

Check if a table has a self-referential FK

Source

pub fn self_referential_tables(&self) -> Vec<TableId>

Get tables that have self-referential FKs

Source

pub fn topo_sort(&self) -> TopoSortResult

Perform topological sort using Kahn’s algorithm.

Returns tables in dependency order (parents before children). Tables that are part of cycles are returned separately.

Source

pub fn processing_order(&self) -> (Vec<TableId>, Vec<TableId>)

Get processing order for sampling/sharding.

Returns all tables in order: first the topologically sorted acyclic tables, then the cyclic tables (which need special handling).

Source

pub fn is_ancestor(&self, ancestor: TableId, descendant: TableId) -> bool

Check if table A is an ancestor of table B (A is referenced by B directly or transitively)

Source

pub fn ancestors(&self, id: TableId) -> Vec<TableId>

Get all ancestor tables of a given table (tables it depends on, directly or transitively)

Source

pub fn descendants(&self, id: TableId) -> Vec<TableId>

Get all descendant tables of a given table (tables that depend on it)

Source

pub fn root_tables(&self) -> Vec<TableId>

Get root tables (tables with no parents/dependencies)

Source

pub fn leaf_tables(&self) -> Vec<TableId>

Get leaf tables (tables with no children/dependents)

Trait Implementations§

Source§

impl Debug for SchemaGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V