def _import_helper( dolt: Dolt, table: str, write_import_file: Callable[[str], None], import_mode: Optional[str] = None, primary_key: Optional[List[str]] = None, commit: Optional[bool] = False, commit_message: Optional[str] = None, commit_date: Optional[datetime.datetime] = None, ) -> None: import_mode = _get_import_mode_and_flags(dolt, table, import_mode) logger.info(f"Importing to table {table} in dolt directory located in {dolt.repo_dir()}, import mode {import_mode}") fname = tempfile.mktemp(suffix=".csv") import_flags = IMPORT_MODES_TO_FLAGS[import_mode] try: write_import_file(fname) args = ["table", "import", table] + import_flags if primary_key: args += ["--pk={}".format(",".join(primary_key))] dolt.execute(args + [fname]) if commit: msg = commit_message or f"Committing write to table {table} in {import_mode} mode" dolt.add(table) dolt.commit(msg, date=commit_date) finally: if os.path.exists(fname): os.remove(fname)
def _add_test_table(dolt: Dolt, table_name: str): dolt.sql(query=f''' CREATE TABLE `{table_name}` ( `name` VARCHAR(32), `adjective` VARCHAR(32), `id` INT NOT NULL, `date_of_death` DATETIME, PRIMARY KEY (`id`) ); ''') dolt.add(table_name) dolt.commit('Created test table')