diff options
| author | Jason Kirtland <jek@discorporate.us> | 2008-08-02 16:32:02 +0000 |
|---|---|---|
| committer | Jason Kirtland <jek@discorporate.us> | 2008-08-02 16:32:02 +0000 |
| commit | 8c261ab7b72974d8a093ae011304ccebbeb96770 (patch) | |
| tree | 42abc853efb96c7073fcbb650fc8e566f2702098 /lib/sqlalchemy/ext | |
| parent | 72a4e6b2657b6e9dad55c2340c87e4b5318f85b0 (diff) | |
| download | sqlalchemy-8c261ab7b72974d8a093ae011304ccebbeb96770.tar.gz | |
- declarative.declarative_base():
takes a 'metaclass' arg, defaulting to DeclarativeMeta
renamed 'engine' arg to 'bind', backward compat
documented
Diffstat (limited to 'lib/sqlalchemy/ext')
| -rw-r--r-- | lib/sqlalchemy/ext/declarative.py | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index f8008ab8b..fd70e6b0b 100644 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -408,12 +408,46 @@ def comparable_using(comparator_factory): return comparable_property(comparator_factory, fn) return decorate -def declarative_base(engine=None, metadata=None, mapper=None, cls=object): +def declarative_base(bind=None, metadata=None, mapper=None, cls=object, + metaclass=DeclarativeMeta, engine=None): + """Construct a base class for declarative class definitions. + + The new base class will be given a metaclass that invokes + `instrument_declarative()` upon each subclass definition, and routes + later Column- and Mapper-related attribute assignments made on the class + into Table and Mapper assignments. See the `declarative` module + documentation for examples. + + cls + Defaults to `object`. A class to use as the base for the generated + declarative base class. + + metaclass + Defaults to `DeclarativeMeta`. A metaclass or __metaclass__ + compatible callable to use as the meta type of the generated + declarative base class. + + metadata + An optional `MetaData` instance. All Tables implicitly declared by + subclasses of the base will share this MetaData. A MetaData instance + will be create if none is provided. The MetaData instance will be + available via the `metadata` attribute of the generated declarative + base class. + + bind + An optional `Connectable`, will be assigned to the `metadata.bind`. + The `engine` keyword argument is a deprecated synonym for `bind`. + + mapper + An optional callable, defaults to `sqlalchemy.orm.mapper`. Will be + used to map subclasses to their Tables. + + """ lcl_metadata = metadata or MetaData() - if engine: - lcl_metadata.bind = engine + if bind or engine: + lcl_metadata.bind = bind or engine class Base(cls): - __metaclass__ = DeclarativeMeta + __metaclass__ = metaclass metadata = lcl_metadata if mapper: __mapper_cls__ = mapper |
