Shannon -jj Behrens wrote:
> I've added my notes to the wiki after incorporating all of your feedback:
>
> Using SQLAlchemy with Pylons:
> http://pylonshq.com/project/pylonshq/wiki/SqlAlchemyWithPylons
>
> If you update it, please send email to this list so that the rest of
> us can benefit from your improvements.
>
> Best Regards,
> -jj
>
>   
Just wondering what is wrong with a simple database.py module

where

database.py

# get appconfig from where every you want. I just have a simple python 
file for this, because
# paste config doesn't suit my development/test environment
psycopg = pool.manage(psycopg, pool_size=10)
engine = create_engine(appconfig.dburi, default_ordering=True)
meta = BoundMetaData(engine)
ctx = SessionContext(create_session)

table1 = Table('mytable', meta, ....)

....
....

In your model.py/or model/__init__.py

import database

class MyModel...
....

mapper(MyModel, database.table1)...

Then in your controller

just

import model
import database

dbsession = databaes.ctx.current

I have a few more convenience methods in database.py for example

def select(myclass, *args):
   return ctx.current.query(myclass).select(*args)

use like in your controller:

rs = database.select(model.MyModel)

Isn't this more straight forward. You can then use this in your unit 
test or anywhere else for that matter (outside of pylons) by simply just 
importing database.py and model.py

......or am I missing something.


Huy

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to