Skip to content

Commit c8ada84

Browse files
committed
no issue - progressively decouple bridge in order to hide it as an implementation detail
1 parent 6364fac commit c8ada84

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+317
-269
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## Next
4+
5+
* [feature] `Bridge::getSchemaManager()` method is moved into the
6+
`DatabaseSession` interface instead. Bridges should now never be used
7+
as a public API for end users.
8+
* [bc] ⚠️ All errors in the `MakinaCorpus\QueryBuilder\Error\Bridge`
9+
namespace are now in the `MakinaCorpus\QueryBuilder\Error\Server` namespace.
10+
* [bc] ⚠️ `FunctionalTestCaseTrait::getBridge()` was renamed to
11+
`FunctionalTestCaseTrait::getDatabaseSession()`.
12+
313
## 1.4.0
414

515
* [feature] ⭐️ Added `DatabaseSession::getVendorName()`, `DatabaseSession::getVendorVersion()`,

docs/content/bridges/error.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ They all inherit from `MakinaCorpus\QueryBuilder\Error\QueryBuilderError`.
1515
## Server errors
1616

1717
All server side errors are exception, when a driver error is caught and supported,
18-
it will be converted to a `MakinaCorpus\QueryBuilder\Error\Bridge\*` exception.
18+
it will be converted to a `MakinaCorpus\QueryBuilder\Error\Server\*` exception.
1919

2020
When an error is not supported then the generic
21-
`MakinaCorpus\QueryBuilder\Error\Bridge\ServerError` is raised.
21+
`MakinaCorpus\QueryBuilder\Error\Server\ServerError` is raised.
2222

2323
## Bridge errors passthrough
2424

@@ -38,10 +38,10 @@ use Doctrine\DBAL\DriverManager;
3838
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder;
3939

4040
$connection = DriverManager::getConnection(['driver' => 'pdo_pgsql', /* ... */]);
41-
$queryBuilder = new DoctrineQueryBuilder($connection);
41+
$bridge = new DoctrineQueryBuilder($connection);
4242

4343
// Here it is:
44-
$queryBuilder->disableErrorConverter();
44+
$bridge->disableErrorConverter();
4545
```
4646

4747
:::info

docs/content/converter/converter.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
**Input value converter** converts user input values **from PHP to SQL**.
88

9-
It is plugged per default in the `Bridge` or `QueryBuilder` instance then
10-
propagated to the `ArgumentBag` instance prior query execution.
9+
It is plugged per default in the `Bridge` instance, hence for the final user
10+
the `QueryBuilder` and `DatabaseSession` instances, then propagated to the
11+
`ArgumentBag` instance prior query execution.
1112

1213
When `ArgumentBag::getAll()` is called, all values are lazily converted from
1314
PHP to SQL using the types that were specified during query building.
@@ -32,8 +33,9 @@ See the [legacy data type matrix](../query/datatype) until the documentation is
3233

3334
**Output value converter** converts user input values **from SQL to PHP**.
3435

35-
It is plugged per default in the `Bridge` or `QueryBuilder` instance then
36-
propagated to the `ResultRow` instance after query execution.
36+
It is plugged per default in the `Bridge` instance, hence for the final user
37+
the `QueryBuilder` and `DatabaseSession` instances, then propagated to the
38+
`ResultRow` instance after query execution.
3739

3840
When you decide to iterate over `ResultRow` instances, by calling
3941
`Result::fetchRow()` then the output converter may be used if you specify
@@ -91,7 +93,7 @@ $escaper = new StandardEscaper();
9193
// Pass here the newly created converter.
9294
$writer = new PostgreSQLWriter($escaper, $converter);
9395

94-
$queryBuilder = new DefaultQueryBuilder();
96+
$session = new DefaultQueryBuilder();
9597
```
9698

9799
### When using a bridge
@@ -102,10 +104,10 @@ by the bridge, hence the different procedure.
102104
```php
103105
use MakinaCorpus\QueryBuilder\Bridge\AbstractBridge;
104106

105-
assert($bridge instanceof AbstractBridge);
107+
assert($session instanceof AbstractBridge);
106108

107109
// Directly register your implementation into the bridge.
108-
$bridge
110+
$session
109111
->getConverterPluginRegistry
110112
->register(
111113
new MyCustomOutputConverter(),

docs/content/introduction/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ While your write your SQL queries, you can, and probably will, provide userland
5050
arbitrary identifiers, such as table names, column names, ... As show below:
5151

5252
```php
53-
$queryBuilder->select('some_table')->column('some_column');
53+
$session->select('some_table')->column('some_column');
5454
```
5555

5656
Those needs escaping, in order to prevent SQL injection or unintential syntax

docs/content/introduction/getting-started.md

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Setting it up is easier than standalone setup:
117117
```php
118118
use Doctrine\DBAL\DriverManager;
119119
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder;
120+
use MakinaCorpus\QueryBuilder\DatabaseSession;
120121

121122
// Create or fetch your doctrine/dbal connection.
122123
$connection = DriverManager::getConnection([
@@ -125,9 +126,19 @@ $connection = DriverManager::getConnection([
125126
]);
126127

127128
// Create the query builder.
128-
$queryBuilder = new DoctrineQueryBuilder($connection);
129+
$session = new DoctrineQueryBuilder($connection);
130+
\assert($session instanceof DatabaseSession);
129131
```
130132

133+
:::warning
134+
For the final user, the *bridge* should be hidden and the
135+
`MakinaCorpus\QueryBuilder\DatabaseSession` exposed instead. The bridge is an
136+
internal component that ties the query builder with a third-party driver.
137+
138+
All useful features are exposed via the `DatabaseSession` whereas the bridge
139+
should remain hidden, as its signature is subject to changes.
140+
:::
141+
131142
:::tip
132143
You don't need to specify the SQL dialect to use, it will be derived from
133144
the `doctrine/dbal` connection automatically, without requiring any extra SQL
@@ -139,7 +150,7 @@ query to do so.
139150
Now we can write a query and execute it directly:
140151

141152
```php
142-
$result = $queryBuilder
153+
$result = $session
143154
->select('users')
144155
->column('*')
145156
->where('id', '[email protected]')
@@ -179,14 +190,25 @@ Setting it up is easier than standalone setup:
179190

180191
```php
181192
use MakinaCorpus\QueryBuilder\Bridge\Pdo\PdoQueryBuilder;
193+
use MakinaCorpus\QueryBuilder\DatabaseSession;
182194

183195
// Create or fetch your PDO connection.
184196
$connection = new \PDO('pgsql:...');
185197

186198
// User facade for you to build SQL queries.
187-
$queryBuilder = new PdoQueryBuilder($connection);
199+
$session = new PdoQueryBuilder($connection);
200+
\assert($session instanceof DatabaseSession);
188201
```
189202

203+
:::warning
204+
For the final user, the *bridge* should be hidden and the
205+
`MakinaCorpus\QueryBuilder\DatabaseSession` exposed instead. The bridge is an
206+
internal component that ties the query builder with a third-party driver.
207+
208+
All useful features are exposed via the `DatabaseSession` whereas the bridge
209+
should remain hidden, as its signature is subject to changes.
210+
:::
211+
190212
:::tip
191213
You don't need to specify the SQL dialect to use, it will be derived from
192214
the `PDO` connection automatically.
@@ -195,7 +217,7 @@ the `PDO` connection automatically.
195217
### 3. Write your query and execute it
196218

197219
```php
198-
$result = $queryBuilder
220+
$result = $session
199221
->select('users')
200222
->column('*')
201223
->where('id', '[email protected]')
@@ -258,7 +280,6 @@ declare (strict_types=1);
258280

259281
namespace App\Controller;
260282

261-
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder;
262283
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
263284
use Symfony\Component\HttpFoundation\Response;
264285
use Symfony\Component\Routing\Annotation\Route;
@@ -267,9 +288,9 @@ class TestingController extends AbstractController
267288
{
268289
#[Route('/testing/query-builder', name: 'testing_query_builder')]
269290
public function testQueryBuilder(
270-
DoctrineQueryBuilder $queryBuilder,
291+
DatabaseSession $session,
271292
): Response {
272-
$result = $queryBuilder
293+
$result = $session
273294
->select('some_table')
274295
->executeQuery()
275296
;
@@ -295,10 +316,10 @@ If you need to use another connection, please read the next chapter.
295316
### Using a query builder for another connection
296317

297318
You may have configured more than one `doctrine/dbal` connection, this bundle
298-
will register as many `MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder`
299-
services as doctrine connections being configured.
319+
will register as many `MakinaCorpus\QueryBuilder\DatabaseSession` services as
320+
doctrine connections being configured.
300321

301-
Each service identifier is `query_builder.doctrine.CONNECTION_NAME` where
322+
Each service identifier is `query_builder.session.CONNECTION_NAME` where
302323
`CONNECTION_NAME` is the Doctrine bundle configured connection identifier.
303324

304325
:::tip

docs/content/introduction/usage.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ almost every method call, exception being the methods that create new
1111
objects that requires you to manipulate.
1212

1313
:::info
14-
In all this page, The `$queryBuilder` variable will always be an instance of `MakinaCorpus\QueryBuilder\QueryBuilder`.
14+
In all this page, The `$queryBuilder` variable will always be an instance of
15+
`MakinaCorpus\QueryBuilder\DatabaseSession` or `MakinaCorpus\QueryBuilder\QueryBuilder`.
1516
The `$result` variable will always be an instance of `MakinaCorpus\QueryBuilder\Result\Result`.
1617
:::
1718

docs/content/query/result.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ you can call `Query::executeQuery()` over your queries, for example:
2424
use Doctrine\DBAL\DriverManager;
2525
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder;
2626

27-
$queryBuilder = new DoctrineQueryBuilder(
27+
$session = new DoctrineQueryBuilder(
2828
DriverManager::getConnection([
2929
'driver' => 'pdo_pgsql',
3030
// ... driver options.
3131
])
3232
);
3333

34-
$result = $queryBuilder
34+
$result = $session
3535
->select('some_table')
3636
->column('*')
3737
->executeQuery()
@@ -48,14 +48,14 @@ You may also directly execute raw SQL code as such:
4848
use Doctrine\DBAL\DriverManager;
4949
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder;
5050

51-
$queryBuilder = new DoctrineQueryBuilder(
51+
$session = new DoctrineQueryBuilder(
5252
DriverManager::getConnection([
5353
'driver' => 'pdo_pgsql',
5454
// ... driver options.
5555
])
5656
);
5757

58-
$result = $queryBuilder
58+
$result = $session
5959
->executeQuery(
6060
<<<SQL
6161
SELECT * FROM "some_table"
@@ -82,14 +82,14 @@ use Doctrine\DBAL\DriverManager;
8282
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder;
8383
use MakinaCorpus\QueryBuilder\Result\ResultRow;
8484

85-
$queryBuilder = new DoctrineQueryBuilder(
85+
$session = new DoctrineQueryBuilder(
8686
DriverManager::getConnection([
8787
'driver' => 'pdo_pgsql',
8888
// ... driver options.
8989
])
9090
);
9191

92-
$result = $queryBuilder
92+
$result = $session
9393
->executeQuery(
9494
<<<SQL
9595
SELECT * FROM "some_table"
@@ -142,7 +142,7 @@ to be passed while iterating.
142142

143143
```php
144144

145-
$result = $queryBuilder
145+
$result = $session
146146
->executeQuery(
147147
<<<SQL
148148
SELECT "id", "name", "email", "created_at" FROM "users"

docs/content/query/schema.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ session was connected.
1414
The schema manager is an object that allows you to introspect and alter your
1515
database schema.
1616

17-
Once you have a functional bridge instance, you may fetch the *schema manager* instance:
17+
Once you have a functional database session instance, you may fetch the
18+
*schema manager* instance:
1819

1920
```php
20-
use MakinaCorpus\QueryBuilder\Bridge\Bridge;
21+
use MakinaCorpus\QueryBuilder\DatabaseSession;
2122

22-
\assert($bridge instanceof Bridge);
23+
\assert($session instanceof DatabaseSession);
2324

24-
$schemaManager = $bridge->getSchemaManager();
25+
$schemaManager = $session->getSchemaManager();
2526
```
2627

2728
`$schemaManager` will be an instance of `MakinaCorpus\QueryBuilder\Schema\SchemaManager`.

docs/content/query/transaction.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Introduction
44

5-
When used in conjunction with a bridge, you may use transactions.
5+
As soon as you have a working `DatabaseSession` instance, you may use transactions.
66

77
SQL transaction supports the given level of features:
88

@@ -16,13 +16,21 @@ Consider that you are manipulating a brige instance, which name is `$brige`, you
1616
simply start a transaction this way:
1717

1818
```php
19-
$transaction = $bridge->beginTransaction();
19+
use MakinaCorpus\QueryBuilder\DatabaseSession;
20+
21+
assert($session instanceof DatabaseSession);
22+
23+
$transaction = $session->beginTransaction();
2024
```
2125

2226
You may also create the stub object for it, then start it later:
2327

2428
```php
25-
$transaction = $bridge->createTransaction();
29+
use MakinaCorpus\QueryBuilder\DatabaseSession;
30+
31+
assert($session instanceof DatabaseSession);
32+
33+
$transaction = $session->createTransaction();
2634

2735
$transaction->isStarted(); // returns false
2836

@@ -42,11 +50,14 @@ $transaction->commit();
4250
Error handling is up to you, we advice writing such algorightm to do it right:
4351

4452
```sql
45-
use MakinaCorpus\QueryBuilder\Error\Bridge\ServerError;
53+
use MakinaCorpus\QueryBuilder\DatabaseSession;
54+
use MakinaCorpus\QueryBuilder\Error\Server\ServerError;
55+
56+
assert($session instanceof DatabaseSession);
4657

4758
$transaction = null;
4859
try {
49-
$transaction = $bridge->beginTransaction();
60+
$transaction = $session->beginTransaction();
5061

5162
// ... you SQL statements here ...
5263

@@ -61,15 +72,17 @@ try {
6172
}
6273
```
6374

64-
Transaction `ROLLBACK` is never issued automatically, one exception stands: if the transaction
65-
objet goes out of scope, when the destructor is called, then `ROLLBACK` is issued.
75+
Transaction `ROLLBACK` is never issued automatically, one exception stands: if
76+
the transaction objet goes out of scope, when the destructor is called, then
77+
`ROLLBACK` is issued.
6678

6779
All transactions must be `COMMIT` explicitely, or will be `ROLLBACK` later.
6880

6981
:::warning
70-
The bridge is a single SQL session, which means that if you start a transaction, it will
71-
remain in memory until it is being commited or rollbacked. Code later in stack will issue
72-
SQL queries in the same transaction until it's finished.
82+
Transaction is shared for the `DatabaseSession` instance which means that if
83+
you start a transaction, it will remain in memory until it is being commited
84+
or rollbacked. Code later in stack will issue SQL queries in the same
85+
transaction until it's finished.
7386
:::
7487

7588
## Savepoints

src/Bridge/AbstractBridge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use MakinaCorpus\QueryBuilder\Converter\Converter;
88
use MakinaCorpus\QueryBuilder\Converter\ConverterPluginRegistry;
99
use MakinaCorpus\QueryBuilder\DefaultQueryBuilder;
10-
use MakinaCorpus\QueryBuilder\Error\Bridge\TransactionError;
1110
use MakinaCorpus\QueryBuilder\Error\QueryBuilderError;
11+
use MakinaCorpus\QueryBuilder\Error\Server\TransactionError;
1212
use MakinaCorpus\QueryBuilder\Error\UnsupportedFeatureError;
1313
use MakinaCorpus\QueryBuilder\Escaper\Escaper;
1414
use MakinaCorpus\QueryBuilder\Expression;

src/Bridge/Bridge.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace MakinaCorpus\QueryBuilder\Bridge;
66

77
use MakinaCorpus\QueryBuilder\DatabaseSession;
8-
use MakinaCorpus\QueryBuilder\Schema\SchemaManager;
98
use MakinaCorpus\QueryBuilder\Writer\Writer;
109

1110
interface Bridge extends DatabaseSession
@@ -54,13 +53,6 @@ public function isVersionGreaterOrEqualThan(string $version): bool;
5453
*/
5554
public function getWriter(): Writer;
5655

57-
/**
58-
* Get schema manager.
59-
*
60-
* @experimental
61-
*/
62-
public function getSchemaManager(): SchemaManager;
63-
6456
/**
6557
* Free everything.
6658
*/

0 commit comments

Comments
 (0)