def __init__(self, db): if isinstance(db, Database): self.db = db elif isinstance(db, dict): self.db = connect(**db) elif isinstance(db, str): self.db = connect(db) else: raise ValueError("db 参数类型错误")
def __init__(self, db): if isinstance(db, Database): self.db = db elif isinstance(db, engine.base.Engine) or hasattr(db, "cursor"): self.db = connect(driver=db) elif isinstance(db, dict): self.db = connect(**db) elif isinstance(db, str): self.db = connect(db) else: raise ValueError("db 参数类型错误")
def setUpClass(cls): # path = cls.get_file_path("src.db") # path = "sqlite:///" + path cls.db = connect("sqlite:///:memory:") create_src = """CREATE TABLE "src" ("uuid" INTEGER NOT NULL,"full_name" TEXT,PRIMARY KEY ("uuid"))""" cls.db.execute(create_src) create_dst = """CREATE TABLE "dst" ("id" INTEGER NOT NULL,"name" TEXT,PRIMARY KEY ("id"))""" cls.db.execute(create_dst) cls.db.get_table("src").insert(cls.src_record)
def setUpClass(cls): cls.db = connect(":memory:", driver="sqlite3")
def setUpClass(cls): cls.db = connect("sqlite:///:memory:")
def test_sqlalchemy_driver(self): with connect("sqlite:///:memory:") as db: db.execute("select 1") engine = create_engine("sqlite:///:memory:") with connect(driver=engine) as db: db.execute("select 1")
def test_common_driver(self): with connect(":memory:", driver="sqlite3") as db: db.execute("select 1") con = sqlite3.connect(":memory:") with connect(driver=con) as db: db.execute("select 1")
def get_db(): return connect(":memory:", driver="sqlite3")
def get_db(): return connect("sqlite:///:memory:")
def get_db(): return connect("hive://localhost:10000/default")
def __init__(self, uri, table_name, condition=None): self.db = connect(uri) self.table_name = table_name self.condition = condition if condition else "1=1"