MySQL DB-Api

Robert Rawlins robert.rawlins at thinkbluemedia.co.uk
Wed Mar 12 10:33:07 EDT 2008


Hello guys, sorry for dragging this to the top of the list again but I
really am intrigued to get your feedback.

 

I'm looking for a clean and efficient way to implement the DB-API into my
application without having to create database connections for every instance
of objects which require it.

 

I'd love to create some form of cached instance of the connection within the
application and then provide new cursor instances for objects that need to
query the database but I'm not sure of the best way to deal with this to
ensure the cursors are closed when the instances destruct, or just as
importantly, if I even need to close the cursor.

 

I'd be really interested to know how you are implementing this kind of
thing,

 

Cheers,

 

Robert

 

From: python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.org
[mailto:python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.org]
On Behalf Of Robert Rawlins
Sent: 11 March 2008 11:24
To: python-list at python.org
Subject: MySQL DB-Api

 

Good morning list.

 

I'm in the process of learning my way around the DB-API module for MySQL and
wanted to come and get some advice on how you all manage your database
connections and cursors.

 

Within my applications I'll have many classes which access the database, I'm
wondering to what level I should extract the database connection. 

 

Should I create a new database connection and close it for every method
which calls the database? Should I create the connection/cursor  to the DB
when I construct the class and place the cursor in the self scope? Or should
I create a application wide connection/cursor to the database and inject the
cursor into all the classes which require it?

 

All classes within the application access the same database so at the moment
I'm leaning towards creating an application wide connection and cursor and
then injecting it into classes which require database access, does that
sound like a fair plan?

 

I'm just interested to learn how you are managing this.

 

Thanks guys,

 

Rob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080312/a275775b/attachment-0001.html>


More information about the Python-list mailing list