Package bazaar :: Module core :: Class Bazaar
[show private | hide private]
[frames | no frames]

Type Bazaar

object --+
         |
        Bazaar


The interface to get, modify, find and perform other tasks on application objects.

See Also: Broker bazaar.motor.Motor

Method Summary
  __init__(self, cls_list, config, dsn, dbmod, seqpattern)
Start the Bazaar ORM layer.
  add(self, obj)
Add object to database.
  closeDBConn(self)
Close database connection.
  commit(self)
Commit pending database transactions.
  connectDB(self, dsn)
Make new database connection.
  delete(self, obj)
Delete object from database.
  find(self, cls, query, param, field)
Find objects of given class in database.
  get(self, cls, key)
Get object with key.
  getObjects(self, cls)
Get list of application objects.
  init(self)
Initialize the Bazaar ORM layer.
  parseConfig(self, config)
Parse Bazaar ORM configuration.
  reloadObjects(self, cls, now)
Reload objects from database.
  rollback(self)
Rollback database transactions.
  setConfig(self, config)
Set Bazaar ORM configuration.
  update(self, obj)
Update object in database.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Instance Variable Summary
  brokers: Dictionary of brokers.
  cls_list: List of application classes.
  dbmod: Python DB API module.
  dsn: Python DB API database source name.
  motor: Database access object.

Method Details

__init__(self, cls_list, config=None, dsn='', dbmod=None, seqpattern=None)
(Constructor)

Start the Bazaar ORM layer.

If database source name is not empty, then database connection is created.
Parameters:
cls_list - List of application classes.
config - Configuration object.
dsn - Database source name.
dbmod - Python DB API module.
seqpattern - Sequence command pattern.
Overrides:
__builtin__.object.__init__

See Also: bazaar.core.Bazaar.connectDB, bazaar.config

add(self, obj)

Add object to database.
Parameters:
obj - Object to add.

closeDBConn(self)

Close database connection.

See Also: bazaar.core.Bazaar.connectDB

commit(self)

Commit pending database transactions.

connectDB(self, dsn=None)

Make new database connection.

New database connection is created with specified database source name, which must conform to Python DB API Specification, i.e.:
   bazaar.connectDB('dbname=addressbook host=localhost port=5432 user=bird')
It is possible to reconnect with previous database source name, too:
   bazaar.connectDB()
Parameters:
dsn - Database source name.

See Also: bazaar.core.Bazaar.closeDBConn

delete(self, obj)

Delete object from database.

Object's primary key value is set to None.
Parameters:
obj - Object to delete.

find(self, cls, query, param=None, field=0)

Find objects of given class in database.

The method can be used in two ways.

First, simple dictionary can be passed as query:
   # iterator is returned, so its next() method is used to get
   # the object
   apple = bazaar.find(Article, {'name': 'apple'}).next()
Dictionary can contain objects as values, i.e.:
   bazaar.find(OrderItem, {'article': art})
Second, it is possible to use full power of SQL language:
   # find orders and their articles if order amount is greater
   # than 50$

   # find orders with the query
   query = """
       select O.__key__ from "order" O
       left outer join order_item OI on O.__key__ = OI.order_fkey
       left outer join article A on OI.article_fkey = A.__key__
       group by O.__key__ having sum(A.price) > 50
   """

   for ord in  bzr.find(Order, query):
       print ord                     # show order
       for oi in ord.items:          # show order's articles
           print oi.article
Parameters:
cls - Application class.
query - SQL query or dictionary.
param - SQL query parameters.
field - SQL column number which describes found objects' primary key values.
Returns:
Iterator of found objects.

get(self, cls, key)

Get object with key.
Parameters:
cls - Application class.
key - Object key.

getObjects(self, cls)

Get list of application objects.

Only objects of specified class are returned.
Parameters:
cls - Application class.

See Also: bazaar.core.Bazaar.reloadObjects

init(self)

Initialize the Bazaar ORM layer.

parseConfig(self, config)

Parse Bazaar ORM configuration.
Parameters:
config - Bazaar ORM configuration.

See Also: setConfig bazaar.config.Config bazaar.config.CPConfig

reloadObjects(self, cls, now=False)

Reload objects from database.

If objects immediate reload is requested, then method returns iterator of objects being loaded from database.
Parameters:
cls - Application class.
now - Reload objects immediately.

See Also: bazaar.core.Bazaar.getObjects

rollback(self)

Rollback database transactions.

setConfig(self, config)

Set Bazaar ORM configuration.

See Also: parseConfig init bazaar.config.Config bazaar.config.CPConfig

update(self, obj)

Update object in database.
Parameters:
obj - Object to update.

Instance Variable Details

brokers

Dictionary of brokers. Brokers are mapped with its class application.

cls_list

List of application classes.

dbmod

Python DB API module.

dsn

Python DB API database source name.

motor

Database access object.

Generated by Epydoc 2.1 on Tue May 10 18:27:30 2005 http://epydoc.sf.net