Over the weekend I started learning/using sqlalchemy. I've put
together some practice code that works, however, I don't know if my
code is 'correct,' I don't feel like I have a firm grasp of
sqlalchemy.
Following is my code, it's broken up into 2 (very small) files. I'd
appreciate it if the code could be reviewed for incorrect/poor usage
of sqlalchemy.
Generally, I have questions like: should there be only one metadata
object (books_meta.meta) and engine (books_meta.pg_db)?, can the
books_meta.py file contents be used with files other than books.py?,
etc.
# books_meta.py file
from sqlalchemy import schema, engine
pg_db = engine.create_engine("postgres://user:[email protected]:
5432/sample")
meta = schema.MetaData()
meta.bind = pg_db
#books.py file
from library.model import books_meta
from sqlalchemy import schema
def index(self):
books_tbl = schema.Table("books", books_meta.meta, autoload=True)
publishers_tbl = schema.Table("publishers", books_meta.meta,
autoload=True)
c.books = books_tbl.select().execute()
c.publishers = publishers_tbl.select().execute()
return render("/library.html")
Thanks.
-Dan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---