This module is DEPRECATED. Create your own TableModel using spyne.model.complex.TTableModel()
Here’s an example way of using the spyne.model.table.TableModel:
class User(TableModel, DeclarativeBase):
__namespace__ = 'spyne.examples.user_manager'
__tablename__ = 'spyne_user'
user_id = Column(sqlalchemy.Integer, primary_key=True)
user_name = Column(sqlalchemy.String(256))
first_name = Column(sqlalchemy.String(256))
last_name = Column(sqlalchemy.String(256))
Defined this way, SQLAlchemy objects are regular Spyne objects that can be used anywhere the regular Spyne types go. The definition for the User object is quite similar to vanilla SQLAlchemy declarative syntax, save for two elements:
The SQLAlchemy integration is far from perfect at the moment:
If you need any of the above features, you need to separate the Spyne and SQLAlchemy object definitions.
Spyne makes it easy (to an extent) with the following syntax:
class AlternativeUser(TableModel, DeclarativeBase):
__namespace__ = 'spyne.examples.user_manager'
__table__ = User.__table__
Here, The AlternativeUser object is automatically populated using columns from the table definition.
Bases: spyne.model.complex.ComplexModelBase
The main base class for complex types shared by both SQLAlchemy and spyne. Classes that inherit from this class should also inherit from an sqlalchemy.declarative base class. See the SQLAlchemy Integration section for more info.
Bases: sqlalchemy.ext.declarative.api.DeclarativeMeta, spyne.model.complex.ComplexModelMeta
This class uses the information in class definition dictionary to build the _type_info dictionary that spyne relies on. It otherwise leaves SQLAlchemy and its information alone.