On Oct 12, 1:38 pm, Dan06 <[email protected]> wrote:
> Is it better to reflect and map the tables in the meta.py file or just
> create the engine, meta data, and the session in the meta file and
> have each model file reflect and map its respective table? An example
> of the latter follows:

I would recommend something along the lines of the latter. What you
have below looks decent to me (caveat: I only took a brief glance).
Also, I would use different names for a couple things, as noted below.


> # meta.py
> from sqlalchemy import schema, engine, orm
>
> pg_db = engine.create_engine("postgres://
> postgres:[email protected]:5432/sample")
> meta_data = schema.MetaData()
> meta_data.bind = pg_db
>
> unscoped_session = orm.sessionmaker(bind=pg_db, autoflush=True,
> autocommit=False, expire_on_commit=True)
> session = orm.scoped_session(unscoped_session)
> # end meta.py
>
> # books_model.py

Name this book.py.


> from sqlalchemy import schema, orm
> from helloworld.model import meta
>
> books_tbl = schema.Table("books", meta.meta_data, autoload=True)

I'd probably use _table instead of _tbl. As to book vs books, that's a
tricky one. I've tended to name tables using plurals, but sometimes it
seems easier to use singular names.


> class Books(object):

Name this Book, because each instance is a single book.


>     pass
>
> orm.mapper(Books, books_tbl)
> # end books_model.py

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to