# Path: memsql_loader/util/apsw_helpers.py
# class _NoDefault(object):
# class _RowBase(object):
# class Row(_RowBase):
# class SelectResult(list):
#     def __init__(self, fields, values):
#     def get(self, name, default=_NoDefault):
#     def set(self, name, value):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def __getitem__(self, name):
#     def __setitem__(self, name, value):
#     def __contains__(self, name):
#     def __iter__(self):
#     def __len__(self):
#     def keys(self):
#     def values(self):
#     def items(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def as_dict(self):
#     def for_json(self):
#     def nope(self, *args, **kwargs):
#     def __init__(self, fields, rows, is_rows=False, RowClass=Row):
#     def width(self):
#     def __getitem__(self, i):
# def query(cursor, query, *params, **kwparams):
# def get(cursor, query, *params, **kwparams):
# 
# Path: memsql_loader/util/log.py
# def setup(log_path=None, stdout_enabled=True):
# def update_verbosity(debug=False, extra_verbose=False):
#     def __call__(self, parser, namespace, value, option_string=None):
#     def __call__(self, parser, namespace, value, option_string=None):
#     def __call__(self, parser, namespace, value, option_string=None):
# def configure(parser):
# def get_logger(name, level=None):
#     def format(self, record):
#     def __init__(self, name, level=logging.DEBUG):
# class _SetDebug(argparse.Action):
# class _SetStdout(argparse.Action):
# class _SetLogPath(argparse.Action):
# class Formatter(logging.Formatter):
# class Logger(logging.Logger):
# 
# Path: memsql_loader/loader_db/storage.py
# class LoaderStorage(APSWStorage):
#     _instance = None
#     _initialized = False
#     _instance_lock = multiprocessing.RLock()
# 
#     # We use LoaderStorage as a singleton.
#     def __new__(cls, *args, **kwargs):
#         with cls._instance_lock:
#             if cls._instance is None:
#                 cls._instance = super(LoaderStorage, cls).__new__(
#                     cls, *args, **kwargs)
#                 cls._initialized = False
#             return cls._instance
# 
#     @classmethod
#     def drop_database(cls):
#         with cls._instance_lock:
#             if os.path.isfile(get_loader_db_path()):
#                 os.remove(get_loader_db_path())
#             if os.path.isfile(get_loader_db_path() + '-shm'):
#                 os.remove(get_loader_db_path() + '-shm')
#             if os.path.isfile(get_loader_db_path() + '-wal'):
#                 os.remove(get_loader_db_path() + '-wal')
#             cls._instance = None
# 
#     @classmethod
#     @contextlib.contextmanager
#     def fork_wrapper(cls):
#         # This context manager should be used around any code that forks new
#         # processes that will use a LoaderStorage object (e.g. Worker objects).
#         # This ensures that we don't share SQLite connections across forked
#         # processes.
#         with cls._instance_lock:
#             if cls._instance is not None:
#                 cls._instance.close_connections()
#                 # We garbage collect here to clean up any SQLite objects we
#                 # may have missed; this is important because any surviving
#                 # objects post-fork will mess up SQLite connections in the
#                 # child process.  We use generation=2 to collect as many
#                 # objects as possible.
#                 gc.collect(2)
#         yield
#         with cls._instance_lock:
#             if cls._instance is not None:
#                 cls._instance.setup_connections()
# 
#     def __init__(self):
#         with LoaderStorage._instance_lock:
#             # Since this is a singleton object, we don't want to call the
#             # parent object's __init__ if we've already instantiated this
#             # object in __new__.  However, we may have closed this object's
#             # connections in fork_wrapper above; in that case, we want to set
#             # up new database connections.
#             if not LoaderStorage._initialized:
#                 super(LoaderStorage, self).__init__(get_loader_db_path())
#                 LoaderStorage._initialized = True
#                 return
#             elif not self._db or not self._db_t:
#                 self.setup_connections()


from memsql_loader.util import apsw_helpers, log
from memsql_loader.loader_db.storage import LoaderStorage

class Api(object):
    name = None

    def __init__(self):
        self.logger = log.get_logger(self.name or 'api')

# Path: memsql_loader/util/apsw_helpers.py
# class _NoDefault(object):
# class _RowBase(object):
# class Row(_RowBase):
# class SelectResult(list):
#     def __init__(self, fields, values):
#     def get(self, name, default=_NoDefault):
#     def set(self, name, value):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def __getitem__(self, name):
#     def __setitem__(self, name, value):
#     def __contains__(self, name):
#     def __iter__(self):
#     def __len__(self):
#     def keys(self):
#     def values(self):
#     def items(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def as_dict(self):
#     def for_json(self):
#     def nope(self, *args, **kwargs):
#     def __init__(self, fields, rows, is_rows=False, RowClass=Row):
#     def width(self):
#     def __getitem__(self, i):
# def query(cursor, query, *params, **kwparams):
# def get(cursor, query, *params, **kwparams):
# 
# Path: memsql_loader/util/log.py
# def setup(log_path=None, stdout_enabled=True):
# def update_verbosity(debug=False, extra_verbose=False):
#     def __call__(self, parser, namespace, value, option_string=None):
#     def __call__(self, parser, namespace, value, option_string=None):
#     def __call__(self, parser, namespace, value, option_string=None):
# def configure(parser):
# def get_logger(name, level=None):
#     def format(self, record):
#     def __init__(self, name, level=logging.DEBUG):
# class _SetDebug(argparse.Action):
# class _SetStdout(argparse.Action):
# class _SetLogPath(argparse.Action):
# class Formatter(logging.Formatter):
# class Logger(logging.Logger):
# 
# Path: memsql_loader/loader_db/storage.py
# class LoaderStorage(APSWStorage):
#     _instance = None
#     _initialized = False
#     _instance_lock = multiprocessing.RLock()
# 
#     # We use LoaderStorage as a singleton.
#     def __new__(cls, *args, **kwargs):
#         with cls._instance_lock:
#             if cls._instance is None:
#                 cls._instance = super(LoaderStorage, cls).__new__(
#                     cls, *args, **kwargs)
#                 cls._initialized = False
#             return cls._instance
# 
#     @classmethod
#     def drop_database(cls):
#         with cls._instance_lock:
#             if os.path.isfile(get_loader_db_path()):
#                 os.remove(get_loader_db_path())
#             if os.path.isfile(get_loader_db_path() + '-shm'):
#                 os.remove(get_loader_db_path() + '-shm')
#             if os.path.isfile(get_loader_db_path() + '-wal'):
#                 os.remove(get_loader_db_path() + '-wal')
#             cls._instance = None
# 
#     @classmethod
#     @contextlib.contextmanager
#     def fork_wrapper(cls):
#         # This context manager should be used around any code that forks new
#         # processes that will use a LoaderStorage object (e.g. Worker objects).
#         # This ensures that we don't share SQLite connections across forked
#         # processes.
#         with cls._instance_lock:
#             if cls._instance is not None:
#                 cls._instance.close_connections()
#                 # We garbage collect here to clean up any SQLite objects we
#                 # may have missed; this is important because any surviving
#                 # objects post-fork will mess up SQLite connections in the
#                 # child process.  We use generation=2 to collect as many
#                 # objects as possible.
#                 gc.collect(2)
#         yield
#         with cls._instance_lock:
#             if cls._instance is not None:
#                 cls._instance.setup_connections()
# 
#     def __init__(self):
#         with LoaderStorage._instance_lock:
#             # Since this is a singleton object, we don't want to call the
#             # parent object's __init__ if we've already instantiated this
#             # object in __new__.  However, we may have closed this object's
#             # connections in fork_wrapper above; in that case, we want to set
#             # up new database connections.
#             if not LoaderStorage._initialized:
#                 super(LoaderStorage, self).__init__(get_loader_db_path())
#                 LoaderStorage._initialized = True
#                 return
#             elif not self._db or not self._db_t:
#                 self.setup_connections()


# Path: memsql_loader/api/base.py
from memsql_loader.util import apsw_helpers, log
from memsql_loader.loader_db.storage import LoaderStorage


class Api(object):
    name = None

    def __init__(self):
        self.logger = log.get_logger(self.name or 'api')

        self.storage = LoaderStorage()