The Database object provides easy access to the Draco system
database. The system database is used by Draco to implement some of its
functionality and the can make use of it too. The details of connecting to
the database, authentication and possibly connection persistence are all
handled by Draco. A global instance of this object is stored in the current
module under the name database
.
Complementary to the database
object, a module is available that
provides access to the
DB-API
of the underlying database. This module also stored in
draco.database
, under the name dbapi
. For MySQL databases this
is the MySQLdb module, for PostgreSQL databases this is the
psycopg module.
The following code fragment illustrates how to use these two objects:
from draco.database import database, dbapi cursor = database.cursor() try: cursor.execute('select * from orders') except dbapi.Error: # error!
) |
The public methods or Database are:
) |
) |
) |
connection().commit()
.
) |
connection().rollback()
.