function testRef() { foreach ($this->table->find() as $row) { foreach ($row->allOf("reftest") as $ref) { $this->assertEquals($row->id->get(), $ref->ofWhich("test")->current()->id->get()); } } }
/** * @param \pq\Gateway\Table $table */ function __construct(Table $table) { $cache = $table->getMetadataCache(); if (!($this->columns = $cache->get("{$table}:identity"))) { $table->getQueryExecutor()->execute(new \pq\Query\Writer(IDENTITY_SQL, array($table->getName())), function ($result) use($table, $cache) { $this->columns = array_map("current", $result->fetchAll(\pq\Result::FETCH_ARRAY)); $cache->set("{$table}:identity", $this->columns); }); } }
/** * @param \pq\Gateway\Table $table */ function __construct(Table $table) { $cache = $table->getMetadataCache(); if (!($this->columns = $cache->get("{$table}:attributes"))) { $table->getQueryExecutor()->execute(new \pq\Query\Writer(ATTRIBUTES_SQL, array($table->getName())), function ($result) use($table, $cache) { foreach ($result->fetchAll(\pq\Result::FETCH_OBJECT) as $c) { $this->columns[$c->index] = $this->columns[$c->name] = $c; } $cache->set("{$table}:attributes", $this->columns); }); } }
/** * @param \pq\Gateway\Table $table */ function __construct(Table $table) { $cache = $table->getMetadataCache(); if (!($this->references = $cache->get("{$table}:relations"))) { $table->getQueryExecutor()->execute(new \pq\Query\Writer(RELATION_SQL, array($table->getName())), function ($result) use($table, $cache) { $rel = $result->map([1, 2], null, \pq\Result::FETCH_ASSOC); foreach ($rel as $ref) { foreach ($ref as $table => $key) { $reference = new Reference($key); $this->references[$table][$reference->name] = $reference; } } $cache->set("{$table}:relations", $this->references); }); } }
public function testHstore() { $this->conn->setConverter(new Hstore(new \pq\Types($this->conn))); $row = $this->table->find(["id=" => 3])->current(); $this->assertEquals(null, $row->prop->get()); $data = array("foo" => "bar", "a" => 1, "b" => 2); $row->prop = $data; $row->update(); $this->assertEquals($data, $row->prop->get()); $row->prop["a"] = null; $row->update(); $data["a"] = null; $this->assertEquals($data, $row->prop->get()); unset($data["a"], $row->prop["a"]); $row->update(); $this->assertEquals($data, $row->prop->get()); }
/** * Delete this row in the database * @return \pq\Gateway\Row */ function delete() { $this->table->notify($this, "delete"); $rowset = $this->table->delete($this->criteria(), "*"); if (!count($rowset)) { throw new \UnexpectedValueException("No row deleted"); } $this->data = $rowset->current()->data; return $this->prime(); }
public function testApplyAppend() { $rowset1 = $this->table->find(null, null, 1); $rowset2 = $this->table->find(null, null, 1, 1); $this->assertCount(1, $rowset1); $this->assertCount(1, $rowset2); $rowset2->apply(array($rowset1, "append")); $this->assertCount(1, $rowset2); $this->assertCount(2, $rowset1); }
/** * Delete all rows of this rowset * @param mixed $txn * @return \pq\Gateway\Rowset * @throws \Exception */ function delete($txn = true) { if ($txn && !$txn instanceof pq\Transaction) { $txn = $this->table->getConnection()->startTransaction(); } try { foreach ($this->rows as $row) { $row->delete(); } } catch (\Exception $e) { if ($txn) { $txn->rollback(); } throw $e; } if ($txn) { $txn->commit(); } return $this; }