Module reahl.sqlalchemysupport

Various bits of support for SQLAlchemy and declarative.

For using SqlAlchemy with Reahl

sqlalchemysupport.Session = <sqlalchemy.orm.scoping.scoped_session object at 0x2b0a2efea630>
sqlalchemysupport.Base = <class 'abc.Base'>
sqlalchemysupport.metadata = MetaData(bind=None)

Names of database objects

reahl.sqlalchemysupport.sqlalchemysupport.pk_name(table_name)

Returns the name that will be used in the database for a primary key, given:

Parameters:table_name – The name of the table to which the primary key belongs.
reahl.sqlalchemysupport.sqlalchemysupport.fk_name(table_name, column_name, other_table_name)

Returns the name that will be used in the database for a foreign key, given:

Parameters:
  • table_name – The name of the table from which the foreign key points.
  • column_name – The name of the column in which the foreign key pointer is stored.
  • other_table_name – The name of the table to which this foreign key points.
reahl.sqlalchemysupport.sqlalchemysupport.ix_name(table_name, column_name)

Returns the name that will be used in the database for an index key, given:

Parameters:
  • table_name – The name of the table to which the index belongs.
  • column_name – The name of the column that is indexed.

QueryAsSequence

class reahl.sqlalchemysupport.sqlalchemysupport.QueryAsSequence(query)

Used to wrap a SqlAlchemy Query so that it looks like a normal Python Sequence.

PersistedField

class reahl.sqlalchemysupport.sqlalchemysupport.PersistedField(class_to_query, default=None, required=False, required_message=None, label=None, readable=None, writable=None)

A reahl.component.modelinterface.Field which takes an integer as input, and yields an instance of class_to_query as parsed Python object. The Python object returned is selected from the Session. The instance with ‘id’ equal to the given integer is the one returned.

Parameters:class_to_query – The class to query by id from the Session.

(See reahl.component.modelinterface.Field for other arguments.)

SqlAlchemyControl

class reahl.sqlalchemysupport.sqlalchemysupport.SqlAlchemyControl(echo=False)

An ORMControl for dealing with SQLAlchemy.

nested_transaction()

A context manager for code that needs to run in a nested transaction.

connect()

Creates the SQLAlchemy Engine, bind it to the metadata and instrument the persisted classes for the current reahlsystem.root_egg.

disconnect()

Disposes the current SQLAlchemy Engine and .remove() the Session.

commit()

Commits the current transaction. Programmers should not need to deal with such transaction management explicitly, since the framework already manages transactions itself.

rollback()

Rolls back the current transaction. Programmers should not need to deal with such transaction management explicitly, since the framework already manages transactions itself.

Table Of Contents

Previous topic

Module reahl.sqlitesupport

Next topic

Web framework