def dolt_sql_to_csv(db: dolt.Dolt, sql: str, filename: str, load_args: dict = None): if load_args is None: load_args = {} db.sql(query=sql, result_file=filename, result_format="csv", **load_args) return
def checkout(self, db: dolt.Dolt): res = db.sql( f"select * from dolt_branches where name = '{self.branch}'", result_format="csv") if len(res) == 0: db.sql(f"select dolt_checkout('-b', '{self.branch}')", result_format="csv") else: db.sql(f"select dolt_checkout('{self.branch}')", result_format="csv")
def test_detached_head_cm(doltdb): db = Dolt(doltdb) commits = list(db.log().keys()) with detach_head(db, commits[1]): sum1 = db.sql("select sum(a) as sum from t1", result_format="csv")[0] with detach_head(db, commits[0]): sum2 = db.sql("select sum(a) as sum from t1", result_format="csv")[0] assert sum1["sum"] == "3" assert sum2["sum"] == "6"
def test_set_dolt_path_error(doltdb): db = Dolt(doltdb) set_dolt_path("dolt") test_cmd = "show tables" db.sql(test_cmd, result_format="csv") try: with pytest.raises(FileNotFoundError): set_dolt_path("notdolt") from doltcli.utils import DOLT_PATH assert DOLT_PATH == "notdolt" db.sql(test_cmd, result_format="csv") finally: set_dolt_path("dolt")
def test_dolt_sql_errors(doltdb): db = Dolt(doltdb) with pytest.raises(ValueError): db.sql(result_parser=lambda x: x, query=None) with pytest.raises(ValueError): db.sql(result_parser=2, query="select active_branch()") with pytest.raises(ValueError): db.sql(result_file="file.csv", query=None) with pytest.raises(ValueError): db.sql(result_format="csv", query=None)