Exemplo n.º 1
0
 def fetch_modified_at_hash(self):
     cursor, conn = connection.init()
     cursor.execute(
         f"SELECT load_hash FROM metadata_tables WHERE table_name='{self.table}'"
     )
     result = cursor.fetchone()
     if result is not None:
         result = result[0]
     conn.close()
     return result
Exemplo n.º 2
0
def executeScriptsFromFile(filename):
    # Open and read the file as a single buffer
    fd = open(filename, 'r')
    sqlFile = fd.read()
    fd.close()

    # all SQL commands (split on ';')
    sqlCommands = sqlFile.split(';')

    # Execute every command from the input file
    cursor, conn = connection.init()
    for command in sqlCommands:
        cursor.execute(command)

    conn.close()
Exemplo n.º 3
0
    def run(self, data=None, chunk=1):
        cursor, conn = connection.init()
        if data is None:
            data = pd.read_csv(self.path_to_data,
                               sep=";",
                               encoding="iso-8859-1").to_numpy()

        query_field = ",".join(self.fields)
        query_question_marks = ','.join(['?' for field in self.fields])
        cursor.executemany(
            f"INSERT INTO {self.table} ({query_field}) VALUES ({query_question_marks})",
            data)
        file_hash = self.update_hash(cursor, conn)
        conn.commit()
        print(
            f"Seeder '{self.table}' executado com sucesso (chunk {chunk}) - hash: {file_hash}"
        )
        conn.close()
Exemplo n.º 4
0
 def __init__(self, table: str, file_path_to_export: str):
     self.table = table
     self.file_path_to_export = file_path_to_export
     self.cursor, self.conn = connection.init()
Exemplo n.º 5
0
 def has_data(self):
     cursor, conn = connection.init()
     cursor.execute(f"SELECT COUNT(0) FROM {self.table}")
     result = cursor.fetchone()[0] > 0
     conn.close()
     return result