Example #1
0
def dolt_import_csv(db: dolt.Dolt,
                    tablename: str,
                    filename: str,
                    save_args: dict = None):
    mode = "-c"
    tables = db.ls()
    for t in tables:
        if t.name == tablename:
            mode = "-r"
            break

    filetype = "--file-type csv"

    imp = ["table", "import", filetype, mode, tablename]
    if save_args and "primary_key" in save_args:
        pks = ",".join(save_args["primary_key"])
        imp.append(f"--pk {pks}")

    imp.append(filename)
    db.execute(imp)
Example #2
0
def dolt_export_csv(db: dolt.Dolt,
                    tablename: str,
                    filename: str,
                    load_args: dict = None):
    exp = ["table", "export", "-f", "--file-type", "csv", tablename, filename]
    db.execute(exp)