Gerhard Häring wrote: > Robert Rawlins - Tamed Technology wrote: >> Essentially I only have a single database attached to my application >> but I’m looking for the best way to handle its connection so thought I >> would come and get your thoughts and opinions. >> Within my applications I’ll have many classes which access the >> database, I’m wondering to what level I should extract the database >> connection. [...] > > Be sure to wrap the actual "getting the connection object". > >> Should I create a new database connection and close it for every >> method which calls the database? Should I create the connection to >> the DB when I construct the class and place the cursor in the self >> scope? Or should I create an application wide connection to the >> database and inject the connection into all the classes which require >> it? [...] > > That's what I'd do. But I'd not inject it and rather just get it (like > with get_con() in my example code). > > I've attached example code that shows how DB-API database access can be > simplified. > > -- Gerhard >
Nice. I have a module that abstracts getting the initial connection and attempts a standard URI scheme; http://halfcooked.com/blog/2006/09/20/python-25-and-generic-database-connection-utilities/ Somewhere in the combination is a 'simplified' DB-API fighting to get out ... Regards, Andy -- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ _______________________________________________ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig