def loadTableAsDict( tableName, connFactory=None ): """Load the contents of the named table into a dictionary. Data are RowItemModels representing the contents and keys are the respective row item IDs. """ dataTable = execute("select * from %s" % tableName, includeColumnNames=True, connFactory=connFactory); dataModels = modelListFromTable(dataTable); dataModelsById = modelDictFromList(dataModels, defaultIDColumn(tableName) ); return dataModelsById;
def loadRecordModelById( tableName, idValue, idCol=None, conn=None, connFactory=None ): """Load an individual record model by an ID value that is presumed to exist and be unique. """ if idCol is None: idCol = defaultIDColumn(tableName); query = "select * from %s where %s = %s" % (tableName, idCol, Env.SQL_PLACEHOLDER); params = (idValue,); dataTable = execute( query, params, includeColumnNames=True, conn=conn, connFactory=connFactory); dataModels = modelListFromTable(dataTable); keyModel = dataModels[0]; # Assume that exactly 1 row item will exist return keyModel;