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
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()
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()
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()
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