Skip to content

Commit 2222ea4

Browse files
committed
renamed Nette\Database\Context -> Explorer
1 parent 75ddf0c commit 2222ea4

21 files changed

+59
-33
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Nette Database Explorer layer helps you to fetch database data more easily and i
7171

7272
Let's take a look at common use-case. You need to fetch books and their authors. It is common 1:N relationship. The often used implementation fetches data by one SQL query with table joins. The second possibility is to fetch data separately, run one query for getting books and then get an author for each book by another query (e.g. in your foreach cycle). This could be easily optimized to run only two queries, one for books, and another for the needed authors - and this is just the way how Nette Database Explorer does it.
7373

74-
Selecting data starts with the table, just call `$context->table()` on the `Nette\Database\Context` object. The easiest way to get it is [described here](https://doc.nette.org/database-core#toc-configuration), but if we use Nette Database Explorer alone, it can be [manually created](https://doc.nette.org/database-explorer#toc-manual-creating-nette-database-context).
74+
Selecting data starts with the table, just call `$context->table()` on the `Nette\Database\Explorer` object. The easiest way to get it is [described here](https://doc.nette.org/database-core#toc-configuration), but if we use Nette Database Explorer alone, it can be [manually created](https://doc.nette.org/database-explorer#toc-manual-creating-nette-database-context).
7575

7676

7777
```php

src/Bridges/DatabaseDI/DatabaseExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private function setupDatabase(\stdClass $config, string $name): void
128128
}
129129

130130
$builder->addDefinition($this->prefix("$name.context"))
131-
->setFactory(Nette\Database\Context::class, [$connection, $structure, $conventions])
131+
->setFactory(Nette\Database\Explorer::class, [$connection, $structure, $conventions])
132132
->setAutowired($config->autowired);
133133

134134
if ($this->name === 'database') {

src/Database/Context.php renamed to src/Database/Explorer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515

1616
/**
17-
* Database context.
17+
* Database explorer.
1818
*/
19-
class Context
19+
class Explorer
2020
{
2121
use Nette\SmartObject;
2222

@@ -172,3 +172,6 @@ public static function literal(string $value, ...$params): SqlLiteral
172172
return new SqlLiteral($value, $params);
173173
}
174174
}
175+
176+
177+
class_exists(Context::class);

src/Database/Table/GroupedSelection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Nette\Database\Table;
1111

1212
use Nette;
13-
use Nette\Database\Context;
13+
use Nette\Database\Explorer;
1414
use Nette\Database\IConventions;
1515

1616

@@ -37,7 +37,7 @@ class GroupedSelection extends Selection
3737
* Creates filtered and grouped table representation.
3838
*/
3939
public function __construct(
40-
Context $context,
40+
Explorer $explorer,
4141
IConventions $conventions,
4242
string $tableName,
4343
string $column,
@@ -46,7 +46,7 @@ public function __construct(
4646
) {
4747
$this->refTable = $refTable;
4848
$this->column = $column;
49-
parent::__construct($context, $conventions, $tableName, $cacheStorage);
49+
parent::__construct($explorer, $conventions, $tableName, $cacheStorage);
5050
}
5151

5252

src/Database/Table/Selection.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Nette\Database\Table;
1111

1212
use Nette;
13-
use Nette\Database\Context;
13+
use Nette\Database\Explorer;
1414
use Nette\Database\IConventions;
1515

1616

@@ -22,7 +22,7 @@ class Selection implements \Iterator, IRowContainer, \ArrayAccess, \Countable
2222
{
2323
use Nette\SmartObject;
2424

25-
/** @var Context */
25+
/** @var Explorer */
2626
protected $context;
2727

2828
/** @var IConventions */
@@ -84,20 +84,20 @@ class Selection implements \Iterator, IRowContainer, \ArrayAccess, \Countable
8484
* Creates filtered table representation.
8585
*/
8686
public function __construct(
87-
Context $context,
87+
Explorer $explorer,
8888
IConventions $conventions,
8989
string $tableName,
9090
Nette\Caching\IStorage $cacheStorage = null
9191
) {
92-
$this->context = $context;
92+
$this->context = $explorer;
9393
$this->conventions = $conventions;
9494
$this->name = $tableName;
9595

9696
$this->cache = $cacheStorage
97-
? new Nette\Caching\Cache($cacheStorage, 'Nette.Database.' . md5($context->getConnection()->getDsn()))
97+
? new Nette\Caching\Cache($cacheStorage, 'Nette.Database.' . md5($explorer->getConnection()->getDsn()))
9898
: null;
9999
$this->primary = $conventions->getPrimary($tableName);
100-
$this->sqlBuilder = new SqlBuilder($tableName, $context);
100+
$this->sqlBuilder = new SqlBuilder($tableName, $explorer);
101101
$this->refCache = &$this->getRefTable($refPath)->globalRefCache[$refPath];
102102
}
103103

src/Database/Table/SqlBuilder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Nette\Database\Table;
1111

1212
use Nette;
13-
use Nette\Database\Context;
13+
use Nette\Database\Explorer;
1414
use Nette\Database\IConventions;
1515
use Nette\Database\IStructure;
1616
use Nette\Database\ISupplementalDriver;
@@ -93,12 +93,12 @@ class SqlBuilder
9393
private $expandingJoins = [];
9494

9595

96-
public function __construct(string $tableName, Context $context)
96+
public function __construct(string $tableName, Explorer $explorer)
9797
{
9898
$this->tableName = $tableName;
99-
$this->driver = $context->getConnection()->getSupplementalDriver();
100-
$this->conventions = $context->getConventions();
101-
$this->structure = $context->getStructure();
99+
$this->driver = $explorer->getConnection()->getSupplementalDriver();
100+
$this->conventions = $explorer->getConventions();
101+
$this->structure = $explorer->getStructure();
102102
$tableNameParts = explode('.', $tableName);
103103
$this->delimitedTable = implode('.', array_map([$this->driver, 'delimite'], $tableNameParts));
104104
$this->checkUniqueTableName(end($tableNameParts), $tableName);

src/compatibility.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Nette Framework (https://nette.org)
5+
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Nette\Database;
11+
12+
if (false) {
13+
/** @deprecated use Nette\Database\Explorer */
14+
class Context
15+
{
16+
}
17+
18+
class Context
19+
{
20+
}
21+
} elseif (!class_exists(Context::class)) {
22+
class_alias(Explorer::class, Context::class);
23+
}

tests/Database.DI/DatabaseExtension.basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test('', function () {
4141
Assert::same('sqlite::memory:', $connection->getDsn());
4242

4343
$context = $container->getService('database.default.context');
44-
Assert::type(Nette\Database\Context::class, $context);
44+
Assert::type(Nette\Database\Explorer::class, $context);
4545
Assert::same($connection, $context->getConnection());
4646

4747
Assert::type(Nette\Database\Structure::class, $context->getStructure());

tests/Database.DI/DatabaseExtension.multiple.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ test('', function () {
5151
Assert::same('sqlite::memory:', $connection->getDsn());
5252

5353
$context = $container->getService('database.first.context');
54-
Assert::type(Nette\Database\Context::class, $context);
55-
Assert::same($context, $container->getByType(Nette\Database\Context::class));
54+
Assert::type(Nette\Database\Explorer::class, $context);
55+
Assert::same($context, $container->getByType(Nette\Database\Explorer::class));
5656
Assert::same($connection, $context->getConnection());
5757

5858
Assert::type(Nette\Database\Structure::class, $context->getStructure());

tests/Database/Connection.lazy.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test('non lazy', function () {
2323

2424
test('lazy', function () {
2525
$connection = new Nette\Database\Connection('dsn', 'user', 'password', ['lazy' => true]);
26-
$context = new Nette\Database\Context($connection, new Structure($connection, new DevNullStorage));
26+
$context = new Nette\Database\Explorer($connection, new Structure($connection, new DevNullStorage));
2727
Assert::exception(function () use ($context) {
2828
$context->query('SELECT ?', 10);
2929
}, Nette\Database\DriverException::class, '%a%valid data source %a%');

0 commit comments

Comments
 (0)