Package CHEM :: Package Common :: Module Model
[hide private]
[frames] | no frames]

Module Model



Common objects / base classes used to support DB interactions.

Classes [hide private]
  RowItemModel
Generic object class to model rows from database tables.
  ChemicalSearchModel
Model object to build to define search criteria for chemicals.
  SQLQuery
Helper class to dynamically build a SQL statement.
Functions [hide private]
 
modelListFromTable(results, columnNames=None)
Given a table (2D array) of result items, where each row represents an row / item / object from the database, create an equivalent list of RowItemModels representing those items.
 
modelDictFromList(modelList, columnName, listValues=False)
Given a list of model objects, create a dictionary keyed by the models' values of the columnName attribute with values equal to the corresponding model objects.
 
columnFromModelList(modelList, columnName)
Given a list of model objects and the name of a "column" / attribute, return a list representing a "column" of those values, one from each model object.
Function Details [hide private]

modelListFromTable(results, columnNames=None)

 

Given a table (2D array) of result items, where each row represents an row / item / object from the database, create an equivalent list of RowItemModels representing those items.

If the columnNames are not supplied, then requires that the first row of the results table actually be the names of the columns to key the items of the RowItemModels by. If used the DBUtil.execute method, this is easy as you just need to set the "includeColumnNames" parameter.

modelDictFromList(modelList, columnName, listValues=False)

 

Given a list of model objects, create a dictionary keyed by the models' values of the columnName attribute with values equal to the corresponding model objects.

If listValues is True, rather the dictionary values being the model objects themselves, they will instead be list objects with the models appended into the lists. This would be uninteresting for "unique key" columnNames as it would just create dictionary where every value is a list of size 1. However, this is important for non-unique key columnNames to make sure that model objects from the original list are not overwritten / lost.