Skip to content

Commit 9f0bd28

Browse files
committed
ResultIterator: Update doc
1 parent f872a3a commit 9f0bd28

7 files changed

+52
-34
lines changed

doc/advanced.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ there is no way to know if it more likely that he wanted users from the birth co
5959

6060
This exception message is quite clear on the ambiguity.
6161

62-
Solving ambiguities is always possible by [manually specifying joins](quickstart.html#joins-ans-filters) in your queries.
62+
Solving ambiguities is always possible by [manually specifying joins](quickstart.md#joins-ans-filters) in your queries.
6363

6464
<div class="alert alert-warning">Note: If your data model has a lot of loops, you will likely face a lot of ambiguities. TDBM is very well suited for simple models. If your database model is complex enough to feature several of these loops, maybe TDBM is not the best tool for you. There are other great tools more suited for those use cases like <a href="http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/">Doctrine ORM</a> for instance.</div>

doc/generating_daos.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ The way you generate DAOs and beans **depends on the framework you use**.
4444
TDBM has a feature allowing you to access the database directly through the <code>TDBMService</code>, without generating DAOs or beans.
4545
This is mostly for testing purpose and is not recommended. Should you need it, you can check the <code>tests/TDBMServiceTest.php</code> file for usage samples.</div>
4646

47-
The DAOs and beans structure
47+
The DAOs, beans, resultIterators structure
4848
----------------------------
4949

50-
For each table in your database, TDBM will generate a DAO and a bean. The DAO is the object you will use to
51-
query the database. Each row of the database will be mapped to a bean object.
50+
For each table in your database, TDBM will generate a DAO, a bean and a resultIterator. The DAO is the object you will use to
51+
query the database and will return a bean or a resultIterator. Each row of the database will be mapped to a bean object.
5252

53-
Both DAOs and beans are divided in 2 parts. Let's assume you have a "users" table. TDBM will generate those classes for you:
53+
DAOs, beans and resultIterators are divided in 2 parts. Let's assume you have a "users" table. TDBM will generate those classes for you:
5454

5555

5656
- `AbstractUserDao`: the base class that contains methods to access the "users" table. It is generated by TDBM and you should
@@ -62,6 +62,10 @@ Both DAOs and beans are divided in 2 parts. Let's assume you have a "users" tabl
6262
never modify this class.
6363
- `User`: this class extends AbstractUser. If you have some custom getters and setters, you should implement them in this class. You can
6464
edit it as TDBM will never overwrite it.
65+
- `AbstractUserResultIterator`: the resultIterator representing a query on the "users" table. This class contains methods to specify you query.
66+
It is generated by TDBM and you should never modify this class.
67+
- `UserResultIterator`: this class extends `AbstractUserResultIterator`. If you have some custom function to narrow down your queries you should implement them in this class. You can
68+
edit it as TDBM will never overwrite it.
6569

6670
Let's now have a closer look at the methods that are available in the "UserDao" class:
6771

doc/graphqlite.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class ProductController
186186

187187
/**
188188
* @Query()
189-
* @return Product[]
189+
* @return ProductResultIterator
190190
*/
191191
public function getProducts(Category $category): array
192192
{

doc/images/tdbm_generates_php_classes.png

100755100644
-8.85 KB
Loading

doc/miscellaneous.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class UserDao extends AbstractUserDao {
8989
* Returns the list of users starting with $firstLetter
9090
*
9191
* @param string $firstLetter
92-
* @return User[]
92+
* @return UserResultIterator
9393
*/
9494
public function getUsersByLetter($firstLetter) {
9595
$this->tdbmService->setLogLevel(LogLevel::DEBUG);

doc/quickstart.md

+37-25
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,28 @@ For this tutorial, let's assume a very classic database schema for handling user
1919

2020
![Database schema](images/schema1.png)
2121

22-
DAOs and beans
22+
DAOs, Beans and ResultIterators
2323
--------------
2424

25-
When you [installed TDBM](install.md), you spent some time configuring a connection to your database and then, you generated the DAOs and beans.
25+
When you [installed TDBM](install.md), you spent some time configuring a connection to your database and then, you generated the DAOs, beans and resultIterators.
2626

27-
DAOs are "Data Access Objects". DAOs are classes that will help you access
28-
the objects in your database. There is roughly **one DAO per table in your database**. Each DAO will return "beans". Each row in your database
29-
will be represented by one instance of a bean.
27+
There will be roughly **one class (DAO, Bean, ResultIterator) per table**, in fact only ManyToMany link tables won't get their class.
3028

31-
Each time your database model changes (if you add a new table, a new column, an index or a foreign key...), you will need to regenerate those DAOs and beans.
29+
Each time your database model changes (if you add a new table, a new column, an index or a foreign key...), you will need to regenerate those DAOs, beans and resultIterators.
30+
31+
### DAOs
32+
33+
DAOs are "Data Access Objects". DAOs are classes that will help you access the objects in your database.
34+
Each DAO will return a Bean or a ResultIterator (collection of Beans).
35+
36+
### Beans
37+
38+
Each row in your database will be represented by one instance of a bean.
39+
This instance will allow you to easily update your data using setters and getters strongly typed by TDBM or created by you.
40+
41+
### ResultIterators
42+
43+
A ResultIterator will represent the result of a query. It will allow you to specify it.
3244

3345
Usage sample
3446
------------
@@ -45,7 +57,7 @@ $user = new User("myName");
4557
// Fill the remaining (nullable) columns of the bean using the setters
4658
$user->setPassword(password_hash("myPassword", PASSWORD_DEFAULT));
4759
$user->setMail("[email protected]");
48-
// Any date should be passed as a PHP DateTime or DateTimeImmutable
60+
// Any date should be passed as a PHP DateTimeImmutable
4961
$user->setCreateDate(new DateTimeImmutable());
5062

5163
// Finally, let's save this bean.
@@ -54,9 +66,8 @@ $user->setCreateDate(new DateTimeImmutable());
5466
$userDao->save($user);
5567
```
5668

57-
Since we have a "users" table, TDBM generated
58-
a `UserDao` class and a `User` class. `UserDao` can be used to create/update/delete/search any
59-
user.
69+
Since we have a "users" table, TDBM generated a `UserDao` class, a `User` class and a `UserResultIterator` class.
70+
`UserDao` can be used to create/update/delete/search any user.
6071

6172
You can also notice that the "save()" method is called on the `UserDao`, not on the `User`.
6273

@@ -73,9 +84,6 @@ echo $user->getName();
7384
TDBM will automatically detect the primary key of your table (of course, your table must have a primary key). There is
7485
no name convention to respect, your primary key column can be named anything ('id', 'userid', 'iduser', ...)
7586

76-
To use this method, the primary key must be on a single column. If your primary key is on several columns, you can still use the
77-
search method (see below).
78-
7987
###Querying the database
8088

8189
Now, what about getting the list of all users and displaying their name?
@@ -103,7 +111,7 @@ Bill Shakespeare
103111
```
104112

105113

106-
The `findAll` method will return the list of beans.
114+
The `findAll` method will return the list of beans as a `UserResultIterator`.
107115
Of course, most of the time, you don't want all the rows in a database.
108116
You want to perform a query with filters.
109117

@@ -177,6 +185,10 @@ generated 4 classes:
177185
column of the "users" table. It is generated by TDBM and you should never modify this class.
178186
- `User`: this class extends `AbstractUser`. If you have some custom getters and setters, you should implement them in this class. You can
179187
edit it as TDBM will never overwrite it.
188+
- `AbstractUserResultIterator`: the resultIterator representing a query on the "users" table. This class contains methods to specify you query.
189+
It is generated by TDBM and you should never modify this class.
190+
- `UserResultIterator`: this class extends `AbstractUserResultIterator`. If you have some custom function to narrow down your queries you should implement them in this class. You can
191+
edit it as TDBM will never overwrite it.
180192

181193

182194
In our example, we want to perform a query that retrieves any name starting with a "J". This is a new
@@ -191,7 +203,7 @@ class UserDao extends AbstractUserDao {
191203
* Returns the list of users starting with $firstLetter
192204
*
193205
* @param string $firstLetter
194-
* @return User[]
206+
* @return UserResultIterator
195207
*/
196208
public function findUsersByLetter($firstLetter) {
197209
// The find can be used to retrieve a list of User
@@ -246,7 +258,7 @@ class ProductDao extends AbstractProductDao {
246258
*
247259
* @param Category $category
248260
* @param Store $store
249-
* @return Country[]
261+
* @return CountryResultIterator
250262
*/
251263
public function getProductsByCategoryAndStore(Category $category = null, Store $store = null) {
252264
return $this->find("category = :category AND store = :store", [
@@ -403,7 +415,7 @@ class UserDao extends AbstractUserDao {
403415
* Returns the list of users whose country name starts by "$countryName"
404416
*
405417
* @param string $countryName
406-
* @return User[]
418+
* @return UserResultIterator
407419
*/
408420
public function getUsersByCountryName($countryName) {
409421
// Behold the magic!
@@ -433,7 +445,7 @@ class UserDao extends AbstractUserDao {
433445
* Returns the list of users whose country is "$country"
434446
*
435447
* @param Country $country
436-
* @return User[]
448+
* @return UserResultIterator
437449
*/
438450
public function getUsersByCountry(Country $country) {
439451
// You can pass a Country instance directly to the find method!
@@ -469,7 +481,7 @@ class CountryDao extends AbstractCountryDao {
469481
* Returns the list of countries whose country name starts by "$countryName"
470482
*
471483
* @param string $countryName
472-
* @return Country[]
484+
* @return CountryResultIterator
473485
*/
474486
public function findByCountryName($countryName) {
475487
return $this->find("name LIKE :country", [ 'country' => $countryName.'%' ] );
@@ -492,7 +504,7 @@ class UserDao extends AbstractUserDao {
492504
* Returns the list of users whose country name starts by "$countryName"
493505
*
494506
* @param string $countryName
495-
* @return User[]
507+
* @return UserResultIterator
496508
*/
497509
public function getUsersByCountryName($countryName) {
498510
return $this->find($this->countryDao->findByCountryName($countryName));
@@ -519,7 +531,7 @@ class RightDao extends AbstractRightDao {
519531
* Returns the list of rights for a given user
520532
*
521533
* @param User $user
522-
* @return Right[]
534+
* @return RightResultIterator
523535
*/
524536
public function getRightsForUser(User $user) {
525537
// Behold the magic!
@@ -542,7 +554,7 @@ class RoleDao extends AbstractRoleDao {
542554
/**
543555
* Returns the list of roles where right label = CAN_SING.
544556
*
545-
* @return Role[]
557+
* @return RoleResultIterator
546558
*/
547559
public function getRolesByRightCanSing()
548560
{
@@ -578,7 +590,7 @@ class ProductDao extends AbstractProductDao {
578590
*
579591
* @param int $category_id
580592
* @param int $status
581-
* @return Product[]
593+
* @return ProductResultIterator
582594
*/
583595
public function findProductsByCategoryAndStatus(int $category_id, int $status) {
584596
return $this->find([
@@ -598,7 +610,7 @@ class CountryDao extends AbstractCountryDao
598610
{
599611
/**
600612
* Returns the list of countries ordered by their users count (descending)
601-
* @return Country[]
613+
* @return CountryResultIterator
602614
*/
603615
public function getCountriesByUserCount()
604616
{
@@ -639,7 +651,7 @@ class UserDao extends AbstractUserDao {
639651
/**
640652
* Returns the list of users by alphabetical order
641653
*
642-
* @return User[]
654+
* @return UserResultIterator
643655
*/
644656
public function getUsersByAlphabeticalOrder() {
645657
// The third parameter will be used in the "ORDER BY" clause of the SQL query.

index.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ TDBM is an opiniated ORM. It will not suit everybody and all needs. Here is what
3838

3939
TDBM is a "database first" ORM. Everything starts from your database. TDBM is very good at understanding your database model and the intent behind it. It will generate PHP objects mapping your model.
4040

41+
<!-- https://docs.google.com/drawings/d/1ZdwVgk5w1oFXnVDnDuK6d9uu_zXxNuuzYlyK409zVBE -->
4142
![TDBM generates your PHP classes](doc/images/tdbm_generates_php_classes.png)
4243

4344
TDBM **understands your database model**. From it, it will generate PHP classes that will help you access your database:
4445

4546
- *DAOs* that are services helping you access a given table
46-
- and *Beans* that are classes representing a row in your database.
47+
- *Beans* that are classes representing a row in your database.
48+
- *ResultIterators* that are classes representing a query result.
4749

4850
```php
4951
// Daos are used to query the database
@@ -53,7 +55,7 @@ $user = $userDao->getById(42);
5355
$login = $user->getLogin();
5456
```
5557

56-
Because PHP objects are generated (no magic properties), you get a nice **autocompletion** in your favorite IDE (PHPStorm, Eclipse PDT, Netbeans...).
58+
Because PHP objects are generated (no magic properties), you get a nice **autocompletion** in your favorite IDE (PHPStorm, Eclipse PDT, NetBeans...).
5759

5860
## TDBM is really good at understanding your database model
5961

0 commit comments

Comments
 (0)