SQLAlchemy 0.5 Documentation

Multiple Pages | One Page
Version: 0.5.0rc4 Last Updated: 11/14/08 16:38:11

module sqlalchemy.sql.visitors

Visitor/traversal interface and library functions.

SQLAlchemy schema and expression constructs rely on a Python-centric version of the classic "visitor" pattern as the primary way in which they apply functionality. The most common use of this pattern is statement compilation, where individual expression classes match up to rendering methods that produce a string result. Beyond this, the visitor system is also used to inspect expressions for various information and patterns, as well as for usage in some kinds of expression transformation. Other kinds of transformation use a non-visitor traversal system.

For many examples of how the visit system is used, see the sqlalchemy.sql.util and the sqlalchemy.sql.compiler modules. For an introduction to clause adaption, see http://techspot.zzzeek.org/?p=19 .

Module Functions

def cloned_traverse(obj, opts, visitors)

clone the given expression structure, allowing modifications by visitors.

def iterate(obj, opts)

traverse the given expression structure, returning an iterator.

traversal is configured to be breadth-first.

def iterate_depthfirst(obj, opts)

traverse the given expression structure, returning an iterator.

traversal is configured to be depth-first.

def replacement_traverse(obj, opts, replace)

clone the given expression structure, allowing element replacement by a given replacement function.

def traverse(obj, opts, visitors)

traverse and visit the given expression structure using the default iterator.

def traverse_using(iterator, obj, visitors)

visit the given expression structure using the given iterator of objects.

class ClauseVisitor(object)

Base class for visitor objects which can traverse using the traverse() function.

def chain(self, visitor)

'chain' an additional ClauseVisitor onto this ClauseVisitor.

the chained visitor will receive all visit events after this one.

def iterate(self, obj)

traverse the given expression structure, returning an iterator of all elements.

def traverse(self, obj)

traverse and visit the given expression structure.

def traverse_single(self, obj)
back to section top

class CloningVisitor(ClauseVisitor)

Base class for visitor objects which can traverse using the cloned_traverse() function.

def copy_and_process(self, list_)

Apply cloned traversal to the given list of elements, and return the new list.

def traverse(self, obj)

traverse and visit the given expression structure.

back to section top

class ReplacingCloningVisitor(CloningVisitor)

Base class for visitor objects which can traverse using the replacement_traverse() function.

def replace(self, elem)

receive pre-copied elements during a cloning traversal.

If the method returns a new element, the element is used instead of creating a simple copy of the element. Traversal will halt on the newly returned element if it is re-encountered.

def traverse(self, obj)

traverse and visit the given expression structure.

back to section top

class Visitable(object)

Base class for visitable objects, applies the VisitableType metaclass.

back to section top

class VisitableType(type)

Metaclass which applies a __visit_name__ attribute and _compiler_dispatch method to classes.

def __init__(cls, clsname, bases, dict)

Construct a new VisitableType.

back to section top
Up: API Documentation | Previous: module sqlalchemy.sql.expression | Next: module sqlalchemy.types