(self, database:str, path:str)
| 66 | self._db.close() |
| 67 | |
| 68 | def insert_data(self, database:str, path:str): |
| 69 | csv = FileManager() |
| 70 | db = self._get_connection(database) |
| 71 | file = os.path.basename(path) |
| 72 | index_ext = file.index('.') |
| 73 | file_name = file[:index_ext].lower() |
| 74 | ### Get Dat file structure and information |
| 75 | AnsiPrint.print_locale("import.reading_file", end='\r', filename=file_name) |
| 76 | file_content = csv.get_structure(path) |
| 77 | ## Create Table and Columns |
| 78 | table_columns = file_content.headers |
| 79 | if file_name not in self._summary["tables"]: |
| 80 | self._summary["tables"].append(file_name) |
| 81 | ## Create tables |
| 82 | AnsiPrint.print(f"\rSaving... [cyan]{file_name}[reset] [{len(file_content.rows)}/{len(file_content.rows)}]"+' '*40, end='\r') |
| 83 | db.create_table(file_name, table_columns) |
| 84 | db.insert_many(file_name,file_content.rows, table_columns) |
| 85 | self._summary["rows"]+=len(file_content.rows) |
| 86 | AnsiPrint.print(f"Imported [cyan]{file_name}[green] [Success][reset]"+' '*40) |
| 87 | |
| 88 | def start(self): |
| 89 | old_db = SqlMapSetting().database |
no test coverage detected