<commit_before>from __future__ import print_function

import sqlite3
from .tablenice import TableNice


class SqlNice(object):
    def __init__(self, sqlite_path_db):
        self.conn = sqlite3.connect(sqlite_path_db)
        self.cursor = self.conn.cursor()
        self.table_list_names = self.get_tables_names()
        self.columns_by_tables = self.get_tables_schemas()
        self.table_list_obj = {}

    def create_table(self, table_name, columns, types=None):
        pass

    def drop_table(self, table_name):
        pass

    def get_tables_names(self):
        """
        Take the tables inside the sqlite3 db
        :return:
        List of tables names
        """
        res = self.conn.execute("SELECT name FROM sqlite_master WHERE type='table';")
        return [str(name[0]) for name in res]

    def get_columns_names(self, table_name):
        """
        Take the columns details and add to attributes of the class
        :return:
        List of Columns Names
        """
        self.cursor.execute("SELECT * FROM " + table_name)
        return [name[0] for name in self.cursor.description]

    def get_tables_schemas(self):
        """
        Build a dict with each data from columns by table
        :return:
        Dict with {Table_name: [Columns_names]}
        """
        return {table: self.get_columns_names(table) for table in self.table_list_names}

    def __getitem__(self, item):
        """
        Build the table object if it was requested.
        :param item: Table name
        :return: Dict element of the item
        """
        if item in self.table_list_obj:
            return self.table_list_obj[item]
        else:
            if item in self.table_list_names:
                t = TableNice(item, self.columns_by_tables[item], self.conn)
            else:
                raise Exception('The table ' + str(item) + ' doesn\'t belong to this database')
            self.table_list_obj[item] = t
            return self.table_list_obj[item]
<commit_msg>Adding Connector object and the connect method<commit_after>from __future__ import print_function

import sqlite3
from .tablenice import TableNice


class SqlNice(object, sqlite3):
    def __init__(self, sqlite_path_db):
        # Connection is automatic during the contructor
        self.conn = self.connect(sqlite_path_db)

        self.cursor = self.conn.cursor()
        self.table_list_names = self.get_tables_names()
        self.columns_by_tables = self.get_tables_schemas()
        self.table_list_obj = {}

    def close(self):
        self.conn.close()

    def create_table(self, table_name, columns, types=None):
        pass

    def drop_table(self, table_name):
        pass

    def get_tables_names(self):
        """
        Take the tables inside the sqlite3 db
        :return:
        List of tables names
        """
        res = self.conn.execute("SELECT name FROM sqlite_master WHERE type='table';")
        return [str(name[0]) for name in res]

    def get_columns_names(self, table_name):
        """
        Take the columns details and add to attributes of the class
        :return:
        List of Columns Names
        """
        self.cursor.execute("SELECT * FROM " + table_name)
        return [name[0] for name in self.cursor.description]

    def get_tables_schemas(self):
        """
        Build a dict with each data from columns by table
        :return:
        Dict with {Table_name: [Columns_names]}
        """
        return {table: self.get_columns_names(table) for table in self.table_list_names}

    def __getitem__(self, item):
        """
        Build the table object if it was requested.
        :param item: Table name
        :return: Dict element of the item
        """
        if item in self.table_list_obj:
            return self.table_list_obj[item]
        else:
            if item in self.table_list_names:
                t = TableNice(item, self.columns_by_tables[item], self.conn)
            else:
                raise Exception('The table ' + str(item) + ' doesn\'t belong to this database')
            self.table_list_obj[item] = t
            return self.table_list_obj[item]
{'fraction_non_alphanumeric': 0.08667466986794718, 'fraction_numerical': 0.0024009603841536613, 'mean_word_length': 2.272584446190102, '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': '2312826', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1166, 'n_words': 342}