0.24 Python bindings/Advanced
This page is for advanced objects, not included in the normal import of the bindings, and for most purposes are not needed.
Connection Classes
DBConnection
This connection takes a single input, dbconn, which is a dictionary containing:
- DBUserName
- DBHostName
- DBPassword
- DBName
- DBPort
This class provides automatic connection pooling. All database access is performed through the cursor interface, and in order to maintain thread safety, a single connection will only be shared among cursors of the same thread. If more threads attempt to access the database simultaneously than there are connections, a new single use connection will be opened for that specific cursor.
'release' and 'acquire' methods are available to manage the use of connections in the pool, and to automatically spawn new ones if needed. '__enter__' and '__exit__' exist for use as a context manager, and will return a new cursor to use. Each thread is given its own stack in the context manager, so multiple nested cursors are allowed.
The pool size is adjustable. The default pool size for new connection objects can be set with the 'setDefaultSize' classmethod, and an existing connection can be resized with the 'resizePool' method.
BEConnection
This connection takes the following inputs:
- backend - must be an IP address
- port
- localname=None - if not set, will pull it from socket.gethostname()
- opts=None - a BEConnOpts dictionary providing the capabilities of the connection
- deadline=10 - a float specifying how long a query may wait for a response
FEConnection
XMLConnection
DBCache
BECache
BEEvent
Data Handling Classes
DictData
DBData
DBDataWrite
DBDataRef
DBDataCRef
Assorted Utility
SchemaUpdate
This class is intended to facilitate managing database schema for external plugins. This class must be subclassed, providing a _schema_name string, matching the setting field used to store the schema version. The create method is called if the variable is not set, and up<version> is called to update the schema. The final schema must issue a StopIteration to terminate the loop.
class MySchemaUpdate( SchemaUpdate ): _schema_name = 'MyDBSchemaVer' def create(self): with self.db.cursor(self.log) as cursor: cursor.execute("""CREATE TABLE ....""") return 1000 def up1000(self): with self.db.cursor(self.log) as cursor: cursor.execute("""UPDATE ....""") def up1001(self): with self.db.cursor(self.log) as cursor: cursor.execute("""UPDATE ....""") def up1002(self): raise StopIteration db = MythDB() up = MySchemaUpdate(db) up.run()
This class can also be passed to the DBCache._check_schema() call, or run automatically by setting the _schema_update variable in a DBData class.