~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/ext/declarative/api.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2013-10-28 22:29:40 UTC
  • mfrom: (1.4.24)
  • Revision ID: package-import@ubuntu.com-20131028222940-wvyqffl4g617caun
Tags: 0.8.3-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
218
218
      compatible callable to use as the meta type of the generated
219
219
      declarative base class.
220
220
 
 
221
    .. seealso::
 
222
 
 
223
        :func:`.as_declarative`
 
224
 
221
225
    """
222
226
    lcl_metadata = metadata or MetaData()
223
227
    if bind:
237
241
 
238
242
    return metaclass(name, bases, class_dict)
239
243
 
 
244
def as_declarative(**kw):
 
245
    """
 
246
    Class decorator for :func:`.declarative_base`.
 
247
 
 
248
    Provides a syntactical shortcut to the ``cls`` argument
 
249
    sent to :func:`.declarative_base`, allowing the base class
 
250
    to be converted in-place to a "declarative" base::
 
251
 
 
252
        from sqlalchemy.ext.declarative import as_declarative
 
253
 
 
254
        @as_declarative()
 
255
        class Base(object)
 
256
            @declared_attr
 
257
            def __tablename__(cls):
 
258
                return cls.__name__.lower()
 
259
            id = Column(Integer, primary_key=True)
 
260
 
 
261
        class MyMappedClass(Base):
 
262
            # ...
 
263
 
 
264
    All keyword arguments passed to :func:`.as_declarative` are passed
 
265
    along to :func:`.declarative_base`.
 
266
 
 
267
    .. versionadded:: 0.8.3
 
268
 
 
269
    .. seealso::
 
270
 
 
271
        :func:`.declarative_base`
 
272
 
 
273
    """
 
274
    def decorate(cls):
 
275
        kw['cls'] = cls
 
276
        kw['name'] = cls.__name__
 
277
        return declarative_base(**kw)
 
278
 
 
279
    return decorate
240
280
 
241
281
class ConcreteBase(object):
242
282
    """A helper class for 'concrete' declarative mappings.