Chapter 12.4.2. sqlhub and Transactions

Remember sqlhub? It’s the object that every model class uses as its connection if an explicit connection wasn’t set directly in the class or using its module’s __connection__ variable. Well, sqlhub can do transactions, too. The benefit is that if you have multiple classes that need to participate in a transaction, you can set it one time in sqlhub. The downside is that you have to manage it properly to make sure you don’t keep transactions around too long. sqlhub has an attribute called threadConnection that you should set to your transaction. All the model classes will use this transaction when they access the DB from the current thread. The threadConnection is stored in the thread local storage, ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.