# Path: implementation/primaries/ExtractMetadata/classes/DataLayer/exceptions.py
# class BadTableException(BaseException):
#     """Invalid table name on data entry"""


from sqlalchemy import create_engine, update
from sqlalchemy.orm import sessionmaker
from sqlalchemy.sql.expression import exists, alias, select, or_
from sqlalchemy import Table, Column, Integer, String, MetaData, \
    ForeignKey, Boolean
from .exceptions import BadTableException
                query = query.where(expr)
            res = list(self.execute(query))
            res = self.to_dict(table, res)
            return res
        else:
            raise BadTableException(
                "table {} not in {}".format(
                    table, self.tables.keys()))

    def query(self, data=None, notdata=None, likedata=None, table="pieces"):
        if self.validate_table(table):
            columns = self.tables[table].columns
            query = self.mk_query(data, table=table)
            query = self.not_query(notdata, columns, query)
            query = self.like_query(likedata, columns, query)
            res = query.all()
            return self.to_dict(table, res)
        else:
            raise BadTableException(
                "table {} not in {}".format(
                    table, self.tables.keys()))

    def mk_query(self, data, table="pieces"):
        if self.validate_table(table):
            session = self.get_session()
            query = session.query(self.tables[table])
            if data is not None:
                query = query.filter_by(**data)
            return query
        else:

# Path: implementation/primaries/ExtractMetadata/classes/DataLayer/exceptions.py
# class BadTableException(BaseException):
#     """Invalid table name on data entry"""


# Path: implementation/primaries/ExtractMetadata/classes/DataLayer/querylayer.py
from sqlalchemy import create_engine, update
from sqlalchemy.orm import sessionmaker
from sqlalchemy.sql.expression import exists, alias, select, or_
from sqlalchemy import Table, Column, Integer, String, MetaData, \
    ForeignKey, Boolean
from .exceptions import BadTableException

                query = query.where(expr)
            res = list(self.execute(query))
            res = self.to_dict(table, res)
            return res
        else:
            raise BadTableException(
                "table {} not in {}".format(
                    table, self.tables.keys()))

    def query(self, data=None, notdata=None, likedata=None, table="pieces"):
        if self.validate_table(table):
            columns = self.tables[table].columns
            query = self.mk_query(data, table=table)
            query = self.not_query(notdata, columns, query)
            query = self.like_query(likedata, columns, query)
            res = query.all()
            return self.to_dict(table, res)
        else:
            raise BadTableException(
                "table {} not in {}".format(
                    table, self.tables.keys()))

    def mk_query(self, data, table="pieces"):
        if self.validate_table(table):
            session = self.get_session()
            query = session.query(self.tables[table])
            if data is not None:
                query = query.filter_by(**data)
            return query
        else:

            raise BadTableException(