On 10/13/06, Huy <[EMAIL PROTECTED]> wrote:
>
> 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.

I'm sorry.  It must be really late at night because I just don't
understand what you're getting at.  Which part are you trying to
simplify?  Can you summarize?

You said, "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."  However, that's half the battle I'm
fighting.  Namely, I don't have app_conf on module load.  If you use a
Python module with globals, it simplifies the code a lot, but it also
means you can't achieve Ben Bangert's dream of running multiple
applications in the same process configured with different .ini files.

My requirements are thus:
* Use the .ini file specified on the command line.
* Use autoload=True, which requires that I have a database connection
when loading the schema.

How the various pieces of the model are laid out in different files
isn't something that I feel compelled to argue about since I think
it's okay if everyone does whatever they want.

/me needs more coffee.

Happy Hacking!
-jj

-- 
The one who gets the last laugh isn't the one who did the laughing,
but rather the one who did the writing.

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