def __init__(self, data_source_name): """ A derived class of BaseHub, serves as a base class for any Relational Database hubs. """ BaseHub.__init__(self) # allowed keys in execute self.execute_keys = set([ 'db', 'proc', 'nocommit', 'sql', 'host_type', 'placeholders', 'replace', 'replace_quote', 'limit', 'offset', 'chunk_size', 'chunk_source', 'chunk_min', 'chunk_total', 'executemany', 'return_type', 'key_column', 'callback', 'debug_show', 'debug_noex' ]) # Default values for execute kwargs self.default_host_type = 'master_host' self.default_return_type = 'tuple' # replace string base for replace functionality in execute self.replace_string = 'REP' # set of return types that require a key_column self.return_type_key_columns = set( ['dict', 'dict_json', 'set', 'set_json']) # One of these keys must be provided to execute self.execute_required_keys = set(['proc', 'sql']) # This data structure is used to map the return_type provided to # execute() to the derived hub method. Derived hub's have to map # their methods by setting the appropriate function reference to # its associated key in valid_return_types. self.valid_return_types = { 'iter': None, 'dict': None, 'dict_json': None, 'tuple': None, 'tuple_json': None, 'set': None, 'set_json': None, 'table': None, 'table_json': None, 'rowcount': None, 'callback': None } # Dictionary of required keys for RDBS datasources self.data_source_req_keys = dict( # required keys req=set(['hub', 'master_host']), # optional keys but if present have additional key requirements databases=set(['name', 'procs']), master_host=set(['host', 'user']), read_host=set(['host', 'user']), dev_host=set(['host', 'user'])) # List of SQL tokens that must follow a WHERE statement self.post_where_tokens = [ 'GROUP BY', 'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET', 'PROCEDURE', 'INTO', 'FOR UPDATE' ] # Validate the information in data_sources is complete # so we can provide the caller with useful messaging # regarding what is missing when a class is instantiated. self.validate_data_source(data_source_name) self.pretty_sql_regex = re.compile('\s+', re.DOTALL) self.default_placeholder = '?' __all__ = [ 'load_procs', # noqa 'get_proc', 'get_data', 'validate_data_source', 'set_execute_rules', 'get_execute_data' ]
def __init__(self, data_source_name): """ A derived class of BaseHub, serves as a base class for any Relational Database hubs. """ BaseHub.__init__(self) # allowed keys in execute self.execute_keys = set(['db', 'proc', 'nocommit', 'sql', 'host_type', 'placeholders', 'replace', 'replace_quote', 'limit', 'offset', 'chunk_size', 'chunk_source', 'chunk_min', 'chunk_total', 'executemany', 'return_type', 'key_column', 'callback', 'debug_show', 'debug_noex']) # Default values for execute kwargs self.default_host_type = 'master_host' self.default_return_type = 'tuple' # replace string base for replace functionality in execute self.replace_string = 'REP' # set of return types that require a key_column self.return_type_key_columns = set(['dict', 'dict_json', 'set', 'set_json']) # One of these keys must be provided to execute self.execute_required_keys = set(['proc', 'sql']) # This data structure is used to map the return_type provided to # execute() to the derived hub method. Derived hub's have to map # their methods by setting the appropriate function reference to # its associated key in valid_return_types. self.valid_return_types = {'iter': None, 'dict': None, 'dict_json': None, 'tuple': None, 'tuple_json': None, 'set': None, 'set_json': None, 'table': None, 'table_json': None, 'rowcount': None, 'callback': None} # Dictionary of required keys for RDBS datasources self.data_source_req_keys = dict( # required keys req=set(['hub', 'master_host']), # optional keys but if present have additional key requirements databases=set(['name', 'procs']), master_host=set(['host', 'user']), read_host=set(['host', 'user']), dev_host=set(['host', 'user'])) # List of SQL tokens that must follow a WHERE statement self.post_where_tokens = ['GROUP BY', 'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET', 'PROCEDURE', 'INTO', 'FOR UPDATE'] # Validate the information in data_sources is complete # so we can provide the caller with useful messaging # regarding what is missing when a class is instantiated. self.validate_data_source(data_source_name) self.pretty_sql_regex = re.compile('\s+', re.DOTALL) self.default_placeholder = '?' __all__ = ['load_procs', # noqa 'get_proc', 'get_data', 'validate_data_source', 'set_execute_rules', 'get_execute_data']