예제 #1
0
파일: test_sql.py 프로젝트: dolthub/doltpy
def sql_server():
    p = None
    d = tempfile.TemporaryDirectory()
    try:
        db_path = os.path.join(d.name, "tracks")
        db = Dolt.init(db_path)
        db.sql("create table tracks (TrackId bigint, Name text)")
        db.sql(
            "insert into tracks values (0, 'Sue'), (1, 'L'), (2, 'M'), (3, 'Ji'), (4, 'Po')"
        )
        db.sql("select dolt_commit('-am', 'Init tracks')")
        p = Popen(args=["dolt", "sql-server", "-l", "trace", "--port", "3307"],
                  cwd=db_path)
        time.sleep(.5)
        yield db
    finally:
        if p is not None:
            p.kill()
        if os.path.exists(d.name):
            shutil.rmtree(d.name)
예제 #2
0
import logging

logger = logging.getLogger()
logger.setLevel(logging.WARNING)

from doltpy.cli import Dolt
from doltpy.cli.write import write_pandas
import pandas as pd

if __name__ == "__main__":
    dolt = Dolt.init("foo")

    df_v1 = pd.DataFrame({"A": [1, 1, 1], "B": [1, 1, 1]})
    df_v2 = pd.DataFrame({"A": [1, 1, 1, 2, 2, 2], "B": [1, 1, 1, 2, 2, 2]})

    write_pandas(dolt=dolt,
                 table="bar",
                 df=df_v1.reset_index(),
                 primary_key=["index"],
                 import_mode="create")
    dolt.add("bar")
    dolt.commit("Initialize bar")

    v1 = list(dolt.log(number="1").keys())[0]

    write_pandas(dolt=dolt,
                 table="bar",
                 df=df_v2.reset_index(),
                 primary_key=["index"],
                 import_mode="update")
    dolt.add("bar")