Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Database: database extensible by row factory

  • Loading branch information...
commit 10771d11b7b2ced14cfa106c29750658a5f77a07 1 parent 3bd4e87
@juzna authored
View
20 Nette/Database/Connection.php
@@ -43,6 +43,9 @@ class Connection extends PDO
/** @var Nette\Caching\Cache */
private $cache;
+ /** @var IRowFactory */
+ private $rowFactory;
+
/** @var array of function(Statement $result, $params); Occurs after query is executed */
public $onQuery;
@@ -119,6 +122,23 @@ public function getCache()
+ public function setRowFactory(IRowFactory $rowFactory)
+ {
+ $this->rowFactory = $rowFactory;
+ }
+
+
+
+ /**
+ * @return IRowFactory
+ */
+ public function getRowFactory()
+ {
+ return $this->rowFactory;
+ }
+
+
+
/**
* Generates and executes SQL query.
* @param string statement
View
31 Nette/Database/IRowFactory.php
@@ -0,0 +1,31 @@
+<?php
+
+/**
+ * This file is part of the Nette Framework (http://nette.org)
+ *
+ * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
+ *
+ * For the full copyright and license information, please view
+ * the file license.txt that was distributed with this source code.
+ */
+
+namespace Nette\Database;
+
+use Nette;
+
+
+
+/**
+ * Information about tables and columns structure.
+ */
+interface IRowFactory
+{
+ /**
+ * Create new entity
+ *
+ * @param array
+ * @param Table\Selection
+ * @return mixed
+ */
+ function createRow(array $data, Table\Selection $table);
+}
View
7 Nette/Database/Table/Selection.php
@@ -493,7 +493,12 @@ protected function execute()
protected function createRow(array $row)
{
- return new ActiveRow($row, $this);
+ if ($factory = $this->connection->getRowFactory()) {
+ return $factory->createRow($row, $this);
+
+ } else {
+ return new ActiveRow($row, $this);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.