Skip to main content

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§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: Rng + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,