/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Public Attributes
NonDbi::MetaDB Class Reference

List of all members.

Public Member Functions

def __init__
def __repr__
def execute
def dbikls_
def kls_
def table_
def session
def __call__

Public Attributes

 dbconf
 engine
 metadata

Detailed Description

Create **one** `MetaDB` instance per database connection , usage::

    off_ = MetaDB("tmp_offline_db")
    off  = off_()                           ## call to pull up a session 

    daq_ = MetaDB("tmp_daqdb")
    daq = daq_()

    YCableMap = off_.dbikls_("CableMap")     ## NB now on the MetaDB instance rather than the session 
    print off.query(YCableMap).count()

    YSTF = daq_.kls_("SFO_TZ_FILE")
    print daq.query(YSTF).count()


No need to diddle with the session kls this way, although could if decide to get sugary.

The initial `session_` approach has difficulties when dealing with multiple DB/sessions, 
multiple ``Session.configure`` causes warnings

The contortions were caused by:

#. sharing metadata with declarative base ?
#. having a single vehicle on which to plant API (the session)

Try again unencumbered by declarative base compatitbility and the meta module

Definition at line 281 of file __init__.py.


Constructor & Destructor Documentation

def NonDbi::MetaDB::__init__ (   self,
  dbconf = None 
)

Definition at line 310 of file __init__.py.

00311                                     :
00312         if not dbconf:
00313             dbconf = os.environ.get('DBCONF','tmp_offline_db')
00314         self.dbconf = dbconf
00315         self.engine = engine_( dbconf )
00316         self.metadata = MetaData()


Member Function Documentation

def NonDbi::MetaDB::__repr__ (   self)

Definition at line 317 of file __init__.py.

00318                       :
00319         return "%s(\"%s\")" % ( self.__class__.__name__, self.dbconf )

def NonDbi::MetaDB::execute (   self,
  sql 
)

Definition at line 320 of file __init__.py.

00321                            :
00322         for _ in self.engine.execute(sql):
00323             yield _

def NonDbi::MetaDB::dbikls_ (   self,
  tn 
)

Definition at line 324 of file __init__.py.

00325                           :
00326         pt = Table( tn      , self.metadata, autoload=True, autoload_with=self.engine )
00327         vt = Table( tn+'Vld', self.metadata, autoload=True, autoload_with=self.engine )
00328         pv = join(  pt , vt , pt.c.SEQNO == vt.c.SEQNO )
00329         Kls = type( 'Y'+tn ,(object,),{})    # dynamic class creation
00330         mapper( Kls , pv , properties={ 'SEQNO':[pt.c.SEQNO, vt.c.SEQNO] })
00331         return Kls

def NonDbi::MetaDB::kls_ (   self,
  tn,
  primary_key = None,
  mapping = None 
)

Definition at line 332 of file __init__.py.

00332                                                           :    
00333         t = Table( tn      , self.metadata, autoload=True, autoload_with=self.engine )
00334         Kls = type( 'Y'+tn ,(object,),{})    # dynamic class creation
00335 
00336         kwa = {}
00337         if primary_key:
00338             log.warn("special handling for delinquent tables with no PK defined")        
00339             assert type(primary_key) in (tuple,list), "unexpected type for primary_key" 
00340             kwa['primary_key'] = map(lambda _:getattr(t.c,_), primary_key )
00341 
00342         if mapping:
00343             log.warn("special attribute/column mapping ")        
00344             assert type(mapping) == dict, "unexpected type for mapping from kls att names to table col names  "
00345             kwa['properties'] = dict((att,getattr(t.c,col)) for att,col in mapping.items())
00346 
00347         mapper( Kls , t , **kwa )
00348         return Kls
00349 
def NonDbi::MetaDB::table_ (   self,
  tn 
)

Definition at line 350 of file __init__.py.

00351                          :
00352         t = Table( tn , self.metadata, autoload=True, autoload_with=self.engine )
00353         return t         
00354 

def NonDbi::MetaDB::session (   self)
Binding is deferred until the last moment

Definition at line 355 of file __init__.py.

00356                      :
00357         """
00358         Binding is deferred until the last moment
00359         """
00360         sess = Session(bind=self.engine)
00361         sess.metadb = self
00362         return sess

def NonDbi::MetaDB::__call__ (   self)

Definition at line 363 of file __init__.py.

00364                       :
00365         return self.session()
00366 


Member Data Documentation

Definition at line 310 of file __init__.py.

Definition at line 310 of file __init__.py.

Definition at line 310 of file __init__.py.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:50:09 for NonDbi by doxygen 1.7.4