summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-04-27 23:37:02 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-04-27 23:37:02 +0000
commit032e358970ba7a54fead5abfeb06d61a7a0422dd (patch)
treec5906fd850d1412bce1189c732e3f49834a78640 /lib/sqlalchemy/ext
parent2ffe47e32bcba0c4f4f5d6669dbd3945443e10dd (diff)
downloadsqlalchemy-032e358970ba7a54fead5abfeb06d61a7a0422dd.tar.gz
fix docs for declarative
Diffstat (limited to 'lib/sqlalchemy/ext')
-rw-r--r--lib/sqlalchemy/ext/declarative.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py
index 9509d4326..f1ab13117 100644
--- a/lib/sqlalchemy/ext/declarative.py
+++ b/lib/sqlalchemy/ext/declarative.py
@@ -8,8 +8,7 @@ used in most cases::
from sqlalchemy.ext.declarative import declarative_base
- engine = create_engine('sqlite://')
- Base = declarative_base(engine)
+ Base = declarative_base()
class SomeClass(Base):
__tablename__ = 'some_table'
@@ -42,7 +41,17 @@ with declarative classes. The ``declarative_base`` base class contains a
``MetaData`` object as well as a dictionary of all classes created against
the base. So to access the above metadata and create tables we can say::
- Base.metadata.create_all()
+ engine = create_engine('sqlite://')
+ Base.metadata.create_all(engine)
+
+The `Engine` created above may also be directly associated with the
+declarative base class using the `engine` keyword argument, where it will
+be associated with the underlying `MetaData` object and allow SQL
+operations involving that metadata and its tables to make use of that
+engine automatically::
+
+ {python}
+ Base = declarative_base(engine=create_engine('sqlite://'))
The ``declarative_base`` can also receive a pre-created ``MetaData``
object::