multi connections system
This commit is contained in:
@@ -7,9 +7,13 @@ use Kletellier\PdoWrapper\QueryBuilder;
|
||||
|
||||
test("create db",function () {
|
||||
$dir = getcwd();
|
||||
$db = Db::init($dir);
|
||||
$db = Db::init($dir,["default","contwo"]);
|
||||
$ret = $db->executeRawQuery("CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, col1 VARCHAR, date1 DATETIME);");
|
||||
expect($ret)->toBe(true);
|
||||
|
||||
$db2 = Db::getInstance("contwo");
|
||||
$ret = $db2->executeRawQuery("CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, col1 VARCHAR, date1 DATETIME);");
|
||||
expect($ret)->toBe(true);
|
||||
});
|
||||
|
||||
test("insert row",function () {
|
||||
@@ -137,4 +141,29 @@ test("where array", function() {
|
||||
expect(count($in))->toBe(2);
|
||||
expect($in[0]->id)->toBe(2);
|
||||
|
||||
});
|
||||
|
||||
test("second connection", function() {
|
||||
$row = new Model();
|
||||
$row->setConnection("contwo");
|
||||
$row->setTable("test");
|
||||
$row->col1 = "test";
|
||||
$row->date1 = new \DateTime();
|
||||
$ret = $row->save();
|
||||
|
||||
$row2 = new Model();
|
||||
$row2->setConnection("contwo");
|
||||
$row2->setTable("test");
|
||||
$row2->col1 = "test2";
|
||||
$row2->date1 = new \DateTime();
|
||||
$ret2 = $row2->save();
|
||||
|
||||
expect($ret)->toBe(true);
|
||||
expect($ret2)->toBe(true);
|
||||
|
||||
$qb = new QueryBuilder("test","id","contwo");
|
||||
$rows = $qb->get();
|
||||
|
||||
expect($rows)->toBeArray();
|
||||
expect(count($rows))->toBe(2);
|
||||
});
|
||||
Reference in New Issue
Block a user