Shannon -jj Behrens wrote: > 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." I'm sorry...I didn't understand what you were trying to achieve. I still don't really, but I do understand the requirement is more involved then what I need SA and pylons for. When I say "get appconfig from where ever", I mean you can call paste directly to load your config file and get the dsn from there (I just don't like the paste/pylons config).
I like using the python feature of modules only being initialised once for things like this, because then I can avoid calling init methods like init_model. > 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 I had heaps of problems with application initialisation with Pylons. I use my SA model in many places, not just in Pylons. This is why I do not use the Pylons/Paste config, because it causes more headaches for *me* then it solves. Maybe I just misunderstand it or don't know how to use it properly, but the last time I tried, I gave up; because it only sort of worked. > , 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. > I guess this is my biggest problem at the moment. I don't really understand what this dream is about ? Is it like the way multiple java servlet apps can be run in apache tomcat under different contexts ? > 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. > we use SA and pylons in very different ways. I stick strictly to the static sa metadata declaration. I like having control of my data model. > 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. > > I agree. I really did want to understand why you were doing the things you were doing, because it seemed more complex then what I was doing, but I see that you have your reasons. > /me needs more coffee. > > > Happy Hacking! > -jj > > Cheers 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 -~----------~----~----~----~------~----~------~--~---
