use_in

igwn_ligolw.dbtables.use_in(ContentHandler)

Modify ContentHandler, a sub-class of igwn_ligolw.ligolw.LIGOLWContentHandler, to cause it to use the DBTable class defined in this module when parsing XML documents. Instances of the ContentHandler class must have an attribute named .connection. No specific mechanism is provided for initializing this attribute, it is left as an exercise for the calling code to arrange for it to be set properly before the ContentHandler is used to parse a document.

When a document is parsed, the value of the .connection attribute will be passed to the DBTable class’ .__init__() method as each table object is created, and thus sets the database connection for all table objects in the document.

Example:

>>> import sqlite3
>>> from igwn_ligolw import ligolw
>>> @use_in
... class MyContentHandler(ligolw.LIGOLWContentHandler):
...     def __init__(self, *args):
...         super(MyContentHandler, self).__init__(*args)
...         self.connection = sqlite3.connection()
...
>>>

Multiple database files can be in use at once by creating a content handler class for each one.