Package wsatools :: Module DataFactory :: Class Table
[hide private]

Class Table

source code


Use this class to store the complete contents of a database table in a local Python data object. However, it must be possible to define a unique row of the table with just a single attribute. This obviates the need to constantly query the database, and provides a nice clear Python solution for access to small data sets (e.g. curation tables). Optimised for the scenario where setCurRow is called once, and getAttr many times. Data is stored as a dict(columnName: columnValuesList).

Instance Methods [hide private]
new empty dictionary

__init__(self, tableName, db=None)
Accesses the default database and extracts the requested table data.
source code
 
setCurRow(self, **kwds)
Sets the current row by finding the row where the specified attribute is equal to the given value.
source code
 
_setCurRow(self, attrName, attrValue, caller)
Sets the current row by finding the row where the specified attribute is equal to the given value.
source code
list
getAll(self, attrName)
Returns the column list of all values for given attribute.
source code
scalar
getAttr(self, attrName, **kwds)
Returns the value of the given attribute in the current row (as set by setCurRow()).
source code
 
updateDetails(self, uidName=None)
Updates the Table object with the latest database values.
source code

Inherited from dict: __cmp__, __contains__, __delitem__, __eq__, __ge__, __getattribute__, __getitem__, __gt__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __repr__, __setitem__, __sizeof__, clear, copy, fromkeys, get, has_key, items, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update, values, viewitems, viewkeys, viewvalues

Inherited from object: __delattr__, __format__, __reduce__, __reduce_ex__, __setattr__, __str__, __subclasshook__

Class Variables [hide private]
  _curRow = None
A dictionary of the current row's values referenced by column name.
  _db = None
A DbSession connection to the database.
  name = ''
Name of the database table mirrored in this object.

Inherited from dict: __hash__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, tableName, db=None)
(Constructor)

source code 

Accesses the default database and extracts the requested table data.

Parameters:
  • tableName (str) - Name of database table to capture.
  • db (DbSession) - Optional alternative database connection.
Returns:
new empty dictionary

Overrides: object.__init__

setCurRow(self, **kwds)

source code 

Sets the current row by finding the row where the specified attribute is equal to the given value. Supply keyword argument as for example: setCurRow(programmeID=101). NB: Keywords must define a unique row (otherwise the row is the first instance of this keyword value).

_setCurRow(self, attrName, attrValue, caller)

source code 

Sets the current row by finding the row where the specified attribute is equal to the given value. NB: This must define a unique row (otherwise the row is the first instance of this keyword value).

getAll(self, attrName)

source code 

Returns the column list of all values for given attribute.

Parameters:
  • attrName (str) - Name of attribute column.
Returns: list
List of all attribute values for a given column.

getAttr(self, attrName, **kwds)

source code 

Returns the value of the given attribute in the current row (as set by setCurRow()). If a keyword is supplied then the attribute value is sought for the row where that keyword value is true instead of the current row.

Parameters:
  • attrName (str) - Name of attribute value to retrieve.
  • kwds (dict) - Optional keyword argument list, to specify a particular row other than the current row, e.g. getAttr('title', programmeID=101). NB: Keywords must define a unique row (otherwise the row is the first instance of this keyword value).
Returns: scalar
Value of the attribute in the current row or the row where the keyword argument value is true.

updateDetails(self, uidName=None)

source code 

Updates the Table object with the latest database values. The current row will be reset unless an unchanged unique ID can be supplied to index the new current row.

Parameters:
  • uidName (str) - Column name that contains the unique ID values in the table that will unchanged.