Ejemplo n.º 1
0
class DatabaseHandler:
    connection = sqlite3.connect('Database.db', check_same_thread=False)
    database_creator = DatabaseCreator(connection)
    database_updater = DatabaseUpdater(connection)
    database_fetcher = DatabaseFetcher(connection)

    def create_table_members(self):
        self.database_creator.create_table_members()

    def create_table_links(self):
        self.database_creator.create_table_links()

    def create_table_codes(self):
        self.database_creator.create_table_codes()

    def update_table_members(self, first_name, last_name, chat_id):
        self.database_updater.update_table_members(first_name, last_name,
                                                   chat_id)

    def update_table_links(self, photo, owner, chat_id):
        self.database_updater.update_table_links(photo, owner, chat_id)

    def update_table_codes(self, code, discount):
        self.database_updater.update_table_codes(code, discount)

    def get_latest_photos(self, quantity):
        return self.database_fetcher.get_latest_photos(quantity)

    def get_all_codes(self):
        return self.database_fetcher.get_codes()
def func_base(percent):
    database = DatabaseCreator(source_dbc, destination_dbc, temp_schema, False)

    database.teardown()
    database.create()
    database.validate_database_create()

    s = Subset(source_dbc, destination_dbc, temp_schema, all_tables)

    s.run_downward(percent)

    database.add_constraints()
    database.validate_constraints()

    norm = SubsetResultNorm(source_dbc, destination_dbc).norm()

    print(percent, norm)
    return norm
 def create(self):
     DatabaseCreator().create_database(self.connection, self.cursor)
Ejemplo n.º 4
0
from db_connect import DbConnect
from database_helper import list_all_tables

if __name__ == '__main__':
    if "--stdin" in sys.argv:
        config_reader.initialize(sys.stdin)
    else:
        config_reader.initialize()

    source_dbc = DbConnect(config_reader.get_source_db_connection_info())
    destination_dbc = DbConnect(
        config_reader.get_destination_db_connection_info())

    temp_schema = 'subset_' + str(uuid.uuid4()).replace('-', '')

    database = DatabaseCreator(source_dbc, destination_dbc, temp_schema, False)
    database.teardown()
    database.create()
    database.validate_database_create()

    # Get list of tables to operate on
    all_tables = list_all_tables(source_dbc.get_db_connection())
    all_tables = [
        x for x in all_tables if x not in config_reader.get_excluded_tables()
    ]

    s = Subset(source_dbc, destination_dbc, temp_schema, all_tables)
    s.run_middle_out()

    if "--no-constraints" not in sys.argv:
        database.add_constraints()