X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=lib%2Fpq%2FGateway%2FTable.php;h=8fc85d7ad748ff68d816aa607afdf9fdfbc8cec1;hp=af84e7f5eb59ed5c0e59c054a48c86bcb6f52620;hb=0e2eb1f13ef60ce9a8709354136c42f7d87b2345;hpb=7045a269b4993d414337fcd7ee1b789b15185af4 diff --git a/lib/pq/Gateway/Table.php b/lib/pq/Gateway/Table.php index af84e7f..8fc85d7 100644 --- a/lib/pq/Gateway/Table.php +++ b/lib/pq/Gateway/Table.php @@ -17,6 +17,11 @@ class Table */ public static $defaultResolver; + /** + * @var \pq\Gateway\Table\CacheInterface + */ + public static $defaultMetadataCache; + /** * @var \pq\Connection */ @@ -47,6 +52,11 @@ class Table */ protected $relations; + /** + * @var \pq\Gateway\Table\CacheInterface + */ + protected $metadataCache; + /** * @param string $table * @return \pq\Gateway\Table @@ -73,6 +83,22 @@ class Table $this->conn = $conn ?: static::$defaultConnection ?: new \pq\Connection; } + /** + * Get the complete PostgreSQL connection string + * @return string + */ + function __toString() { + return sprintf("postgresql://%s:%s@%s:%d/%s?%s#%s", + $this->conn->user, + $this->conn->pass, + $this->conn->host, + $this->conn->port, + $this->conn->db, + $this->conn->options, + $this->getName() + ); + } + /** * Set the rowset prototype * @param mixed $rowset @@ -133,6 +159,26 @@ class Table return $this->exec; } + /** + * Get the metadata cache + * @return \pq\Gateway\Table\CacheInterface + */ + function getMetadataCache() { + if (!isset($this->metadatCache)) { + $this->metadataCache = static::$defaultMetadataCache ?: new Table\StaticCache; + } + return $this->metadataCache; + } + + /** + * Set the metadata cache + * @param \pq\Gateway\Table\CacheInterface $cache + */ + function setMetadataCache(Table\CacheInterface $cache) { + $this->metadataCache = $cache; + return $this; + } + /** * Get foreign key relations * @param string $to fkey @@ -187,7 +233,6 @@ class Table * @return mixed */ protected function execute(QueryWriter $query) { - echo $query,"\n",json_encode($query->getParams()),"\n"; return $this->getQueryExecutor()->execute($query, array($this, "onResult")); }