# 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):


from memsql_loader.util import apsw_helpers

class TableDefinition(object):
    def __init__(self, table_name, sql, index_columns=None):
        self.table_name = table_name
        self.sql = sql
        self.index_columns = index_columns or []

class APSWSQLUtility(object):
    def __init__(self, storage):
        self.storage = storage
        self._tables = {}

    ###############################
    # Public Interface

    def setup(self):
        """ Initialize the required tables in the database """
        with self.storage.transaction() as cursor:
            for table_defn in self._tables.values():
                cursor.execute(table_defn.sql)
                for index_column in table_defn.index_columns:
                    index_name = table_defn.table_name + '_' + index_column + '_idx'
                    cursor.execute(
                        'CREATE INDEX %s ON %s (%s)' %
                        (index_name, table_defn.table_name, index_column))
        return self

    def ready(self):
        """ Returns True if the tables have been setup, False otherwise """
        with self.storage.cursor() as cursor:

# 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/apsw_sql_utility.py
from memsql_loader.util import apsw_helpers


class TableDefinition(object):
    def __init__(self, table_name, sql, index_columns=None):
        self.table_name = table_name
        self.sql = sql
        self.index_columns = index_columns or []

class APSWSQLUtility(object):
    def __init__(self, storage):
        self.storage = storage
        self._tables = {}

    ###############################
    # Public Interface

    def setup(self):
        """ Initialize the required tables in the database """
        with self.storage.transaction() as cursor:
            for table_defn in self._tables.values():
                cursor.execute(table_defn.sql)
                for index_column in table_defn.index_columns:
                    index_name = table_defn.table_name + '_' + index_column + '_idx'
                    cursor.execute(
                        'CREATE INDEX %s ON %s (%s)' %
                        (index_name, table_defn.table_name, index_column))
        return self

    def ready(self):
        """ Returns True if the tables have been setup, False otherwise """
        with self.storage.cursor() as cursor:

            rows = apsw_helpers.query(