> SAContext is a little top-level organizer for engines, metadatas,
> and a session context.  It was written for Pylons due to the
> confusion people were having setting up their models, but the
> SAContext class itself can be used in any SQLAlchemy application.
>
> http://sluggo.scrapping.cc/python/sacontext/
>
hmm, why have i invented same thing 8 months ago...
Anyway. for a reason or another u dont have any "destroy" operations 
there.
Here some i've found useful so far (sorry, not immediately usable):
--------------
    def destroy( me, full =True):
        me.session.close()

        #SA caches/data
        sqlalchemy.clear_mappers()

        try: me.metadata.drop_all()
        except AttributeError: pass
        me.metadata = None
        if full:
            try: me.db.dispose()
            except AttributeError: pass
            me.db = None

        #from sqlalchemy.orm import mapperlib
        #mapperlib.global_extensions[:] = []
        #more?

    #these may be used between make_metadata()/bind() and destroy()
    def destroy_tables( me):
        me.metadata.drop_all()
    def create_tables( me):
        me.metadata.create_all()


def detach_instances( namespace_or_iterable, idname ='id'):
    'useful to completely get rid of any SA sideeffects/artefacts, 
e.g. for testing'
    try: itervalues = namespace_or_iterable.itervalues() #if dict-like
    except AttributeError: itervalues = namespace_or_iterable
    for e in itervalues:
        try: del e._instance_key
        except AttributeError: pass
        setattr( e, idname, None)       #or delattr ??

############
as M.Bayer said in another thread of mine, certain things have 
dependencies so creating/destroying is ordered. 

One thing i'm still not sure, if i can rebind a (now bound) metadata 
to another engine, how that affect mappers etc. i.e. how all these 
lifetimes (engines, metadatas, mappers) actualy interact.

ciao

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to