On Aug 4, 2006, at 5:28 AM, Michele Petrazzo wrote: > Hi list, I'm new to sqlalchemy and I want to say... WOW fantastic > library! > > I'm studying this library because I want to move my worker program to > use sqlalchemy in place of tough sql, so before start, just some > questions: > > - Are there, inside the library the "alter" (drop, etc.) sql function? > I haven't found it.
we have drop, but for "alter" check out http://trac.erosson.com/migrate > - Where are defined "create_session" function? I haven't found it :) its a little tricky to find since its actually an imported class: lib/sqlalchemy/orm/__init__.py which is pointing to : lib/sqlalchemy/orm/session.py -> class Session > - create_session return a session, but how many session can I have > into > my programs? How long does it live? Can I create one and use for > all > my program life (also hours +): > if you want just one session that you use over and over again, you should use a "threadlocal" pattern, assuming your program uses threads. you should generally try to clear() the session as well before using it, as object instances sitting around can lead to much confusion. you should also check out the SessionContext plugin since contextual sessions is what youre looking for: http://www.sqlalchemy.org/docs/plugins.myt#plugins_sessioncontext > def my_class(object): > def __init__(self): > #create all the sql obj > self._mysession = create_session() > > def after_some_hours(self): > self._mysession.query > > - If in a db, I have already "cascade rules", row example: > creation_user integer NOT NULL > REFERENCES _sys_users (id) ON DELETE CASCADE > how I have to wrote the sqlalchemy definitions? Does sqlalchemy > see if > there are already that db rules and work in consequence? Or it will > raise errors? (the I'll delete record, of course) you should be able to have ON DELETE CASCADE set up in your database normally. however, you have to make sure that the mappers you set up contain the relationships that correspond to those cascade rules. What will happen then is if you mark an object instance as deleted, and then flush, SQLAlchemy will also delete the child objects which have been already loaded into memory. therefore, SA will do the deletes before the database's cascade rules get to it. if you dont want to have the relationships set up, then you have to add code in some manner to insure that the cascaded objects get removed from the session when the parent object is deleted. I would advise just trying it out to get a feel for what SA is going to do. > - If a db don't have real "cascade rules" (sqlite), sqlalchemy do the > work for it? yup, just take a look at some of the generated SQL examples in the docs under http://www.sqlalchemy.org/docs/datamapping.myt ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users