Utilities
*********


changeset
=========

sqlalchemy_continuum.utils.changeset(obj)

   Return a humanized changeset for given SQLAlchemy declarative
   object. With this function you can easily check the changeset of
   given object in current transaction.

      from sqlalchemy_continuum import changeset


      article = Article(name=u'Some article')
      changeset(article)
      # {'name': [u'Some article', None]}

   Parameters:
      **obj** -- SQLAlchemy declarative model object


count_versions
==============

sqlalchemy_continuum.utils.count_versions(obj)

   Return the number of versions given object has. This function works
   even when obj has *create_models* and *create_tables* versioned
   settings disabled.

      article = Article(name=u'Some article')

      count_versions(article)  # 0

      session.add(article)
      session.commit()

      count_versions(article)  # 1

   Parameters:
      **obj** -- SQLAlchemy declarative model object


get_versioning_manager
======================

sqlalchemy_continuum.utils.get_versioning_manager(obj_or_class)

   Return the associated SQLAlchemy-Continuum VersioningManager for
   given SQLAlchemy declarative model class or object.

   Parameters:
      **obj_or_class** -- SQLAlchemy declarative model object or class


is_modified
===========

sqlalchemy_continuum.utils.is_modified(obj)

   Return whether or not the versioned properties of given object have
   been modified.

      article = Article()

      is_modified(article)  # False

      article.name = 'Something'

      is_modified(article)  # True

   Parameters:
      **obj** -- SQLAlchemy declarative model object

   See also: "is_modified_or_deleted()"

   See also: "is_session_modified()"


is_modified_or_deleted
======================

sqlalchemy_continuum.utils.is_modified_or_deleted(obj)

   Return whether or not some of the versioned properties of given
   SQLAlchemy declarative object have been modified or if the object
   has been deleted.

   Parameters:
      **obj** -- SQLAlchemy declarative model object


is_session_modified
===================

sqlalchemy_continuum.utils.is_session_modified(session)

   Return whether or not any of the versioned objects in given session
   have been either modified or deleted.

   Parameters:
      **session** -- SQLAlchemy session object

   See also: "is_versioned()"

   See also: "versioned_objects()"


is_versioned
============

sqlalchemy_continuum.utils.is_versioned(obj_or_class)

   Return whether or not given object is versioned.

      is_versioned(Article)  # True

      article = Article()

      is_versioned(article)  # True

   Parameters:
      **obj_or_class** -- SQLAlchemy declarative model object or
      SQLAlchemy declarative model class.

   See also: "versioned_objects()"


parent_class
============

sqlalchemy_continuum.utils.parent_class(version_cls)

   Return the parent class for given version model class.

      parent_class(ArticleVersion)  # Article class

   Parameters:
      **model** -- SQLAlchemy declarative version model class

   See also: "version_class()"


transaction_class
=================

sqlalchemy_continuum.utils.transaction_class(cls)

   Return the associated transaction class for given versioned
   SQLAlchemy declarative class or version class.

      from sqlalchemy_continuum import transaction_class


      transaction_class(Article)  # Transaction class

   Parameters:
      **cls** -- SQLAlchemy versioned declarative class or version
      model class


version_class
=============

sqlalchemy_continuum.utils.version_class(model)

   Return the version class for given SQLAlchemy declarative model
   class.

      version_class(Article)  # ArticleVersion class

   Parameters:
      **model** -- SQLAlchemy declarative model class

   See also: "parent_class()"


versioned_objects
=================

sqlalchemy_continuum.utils.versioned_objects(session)

   Return all versioned objects in given session.

   Parameters:
      **session** -- SQLAlchemy session object

   See also: "is_versioned()"


version_table
=============

sqlalchemy_continuum.utils.version_table(table)

   Return associated version table for given SQLAlchemy Table object.

   Parameters:
      **table** -- SQLAlchemy Table object
