<commit_before>from dataactcore.models.baseInterface import BaseInterface
from dataactcore.config import CONFIG_DB

class ValidatorStagingInterface(BaseInterface):
    """ Manages all interaction with the staging database """

    dbConfig = CONFIG_DB
    dbName = dbConfig['staging_db_name']
    Session = None
    engine = None
    session = None

    def __init__(self):
        self.dbName = self.dbConfig['staging_db_name']
        super(ValidatorStagingInterface, self).__init__()

    @staticmethod
    def getDbName():
        """ Return database name"""
        return ValidatorStagingInterface.dbName

    def dropTable(self,table):
        """

        Args:
            table: Table to be dropped

        Returns:
            True if successful
        """
        self.runStatement("".join(["DROP TABLE ",table]))
        self.session.commit()

    def tableExists(self,table):
        """ True if table exists, false otherwise """
        return self.engine.dialect.has_table(self.engine.connect(),table)

    def countRows(self,table):
        """ Returns number of rows in the specified table """
        if(self.tableExists(table)):
            response =  (self.runStatement("".join(["SELECT COUNT(*) FROM ",table]))).fetchone()[0]
            # Try to prevent blocking
            self.session.close()
            return response
        else:
            return 0

    @staticmethod
    def getTableName(jobId):
        """ Get the staging table name based on the job ID """
        return "".join(["job",str(jobId)])<commit_msg>use ORM instead of SQL statements<commit_after>from dataactcore.models.baseInterface import BaseInterface
from dataactcore.config import CONFIG_DB
from sqlalchemy import MetaData, Table
from sqlalchemy.exc import NoSuchTableError


class ValidatorStagingInterface(BaseInterface):
    """ Manages all interaction with the staging database """

    dbConfig = CONFIG_DB
    dbName = dbConfig['staging_db_name']
    Session = None
    engine = None
    session = None

    def __init__(self):
        self.dbName = self.dbConfig['staging_db_name']
        super(ValidatorStagingInterface, self).__init__()

    @staticmethod
    def getDbName():
        """ Return database name"""
        return ValidatorStagingInterface.dbName

    def dropTable(self,table):
        """

        Args:
            table: Table to be dropped

        Returns:
            True if successful
        """

        metadata = MetaData()
        stagingTable = Table(table, metadata, autoload_with=self.engine)
        stagingTable.drop(bind=self.engine)

    def tableExists(self,table):
        """ True if table exists, false otherwise """
        return self.engine.dialect.has_table(self.engine.connect(),table)

    def countRows(self,table):
        """ Returns number of rows in the specified table """
        metadata = MetaData()
        try:
            stagingTable = Table(table, metadata, autoload_with=self.engine)
        except NoSuchTableError:
            return 0
        rows = self.session.query(stagingTable).count()
        self.session.close()
        return rows

    @staticmethod
    def getTableName(jobId):
        """ Get the staging table name based on the job ID """
        return "".join(["job",str(jobId)])
{'fraction_non_alphanumeric': 0.10024449877750612, 'fraction_numerical': 0.0009168704156479218, 'mean_word_length': 2.6447661469933186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5104073', 'n_tokens_mistral': 892, 'n_tokens_neox': 860, 'n_words': 232}