DBIx::Class::Graph - Represent a graph in a relational database using DBIC


DBIx-Class-Graph documentation Contained in the DBIx-Class-Graph distribution.

Index


Code Index:

NAME

Top

DBIx::Class::Graph

VERSION

Top

version 1.03

SYNOPSIS

Top

  package MySchema::Graph;

  use base 'DBIx::Class';

  __PACKAGE__->load_components("Graph", "Core");
  __PACKAGE__->table("tree");
  __PACKAGE__->add_columns("id", "name", "parent_id");

  __PACKAGE__->connect_graph(predecessor => "parent_id");

  my @children = $rs->get_vertex($id)->successors;

  my @vertices = $rs->vertices;

  # do other cool stuff like calculating distances etc.

DESCRIPTION

Top

This module allows to create and interact with a directed graph. It will take care of storing the information in a relational database. It uses Graph for calculations. This module extends the DBIx::Class::ResultSet. Some methods are added to the resultset, some to the row objects.

NAME

Top

DBIx::Class::Graph - Represent a graph in a relational database using DBIC

CONFIGURATION

Top

load_components

  __PACKAGE__->load_components(qw(Graph Core));

To use this module it has to loaded via load_components in the result class.

resultset_class

XXX

connect_graph(@opt)

    __PACKAGE__->connect_graph( predecessor => 'parent_id' );
    __PACKAGE__->connect_graph( successor   => 'child_id' );
    __PACKAGE__->connect_graph( predecessor => { parents => 'parent_id' } );
    __PACKAGE__->connect_graph( successor   => { childs => 'child_id' } );

The first argument defines how the tree is build. You can either specify predecessor or successor.

The name of the relation to the next vertex is defined by the second argument.

METHODS

Top

ResultSet methods

get_vertex($id)

finds a vertex by searching the underlying resultset for $id in the primary key column (only single primary keys are supported). It's not as smart as the original find in DBIx::Class::ResultSet because it looks on the primary key(s) for $id only.

Result methods

The following methods are imported from Graph:

  delete_vertex connected_component_by_vertex biconnected_component_by_vertex
  weakly_connected_component_by_vertex strongly_connected_component_by_vertex
  is_sink_vertex is_source_vertex is_successorless_vertex is_successorful_vertex
  is_predecessorless_vertex is_predecessorful_vertex is_isolated_vertex is_interior
  is_exterior is_self_loop_vertex successors neighbours predecessors degree
  in_degree out_degree edges_at edges_from edges_to get_vertex_count random_successor
  random_predecessor vertices_at

FAQ

Top

How do I sort the nodes?

Simply sort the resultset

  $rs->search(undef, {order_by => "title ASC"})->graph;

CAVEATS

Top

Multigraph

Multipgraphs are not supported. This means you there can only be one edge per vertex pair and direction.

Speed

you should consider caching the Graph object if you are working with large number of vertices.

SEE ALSO

Top

DBIx::Class::Tree, DBIx::Class::NestedSet

BUGS

Top

See "CAVEATS"

AUTHOR

Top

Moritz Onken, <onken@houseofdesign.de>

I am also avaiable on the DBIx::Class mailinglist

COPYRIGHT AND LICENSE

Top

AUTHOR

Top

Moritz Onken <onken@netcubed.de>

COPYRIGHT AND LICENSE

Top


DBIx-Class-Graph documentation Contained in the DBIx-Class-Graph distribution.

#
# This file is part of DBIx-Class-Graph
#
# This software is Copyright (c) 2010 by Moritz Onken.
#
# This is free software, licensed under:
#
#   The (three-clause) BSD License
#
package DBIx::Class::Graph;
BEGIN {
  $DBIx::Class::Graph::VERSION = '1.03';
}

use Moose;
extends 'DBIx::Class';
with 'DBIx::Class::Graph::Role::Result';

__PACKAGE__->mk_classdata("_graph_rel");
__PACKAGE__->mk_classdata("_graph_foreign_column");
__PACKAGE__->mk_classdata("_graph_column");
__PACKAGE__->mk_classdata("_graph");
__PACKAGE__->mk_classdata("_connect_by");

1;




__END__