Skip to content

Commit 6966556

Browse files
committed
Migrate to composite/db 0.4.0
1 parent ac021fd commit 6966556

File tree

8 files changed

+27
-27
lines changed

8 files changed

+27
-27
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"require": {
1515
"php": "^8.1",
16-
"compositephp/db": "^0.3.1",
16+
"compositephp/db": "^0.4.0",
1717
"iamcal/sql-parser": "^0.4.0",
1818
"nette/php-generator": "^4.0",
1919
"symfony/console": "2 - 6",

src/Generator/CachedTableClassBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ protected function generateFindOne(): ?Method
6464
$this->tableConfig->primaryKeys
6565
);
6666
if (count($this->tableConfig->primaryKeys) === 1) {
67-
$body = 'return $this->createEntity($this->findByPkCachedInternal(' . $this->buildVarsList($this->tableConfig->primaryKeys) . '));';
67+
$body = 'return $this->_findByPkCached(' . $this->buildVarsList($this->tableConfig->primaryKeys) . ');';
6868
} else {
69-
$body = 'return $this->createEntity($this->findOneCachedInternal(' . $this->buildVarsList($this->tableConfig->primaryKeys) . '));';
69+
$body = 'return $this->_findOneCached(' . $this->buildVarsList($this->tableConfig->primaryKeys) . ');';
7070
}
7171

7272
$method = (new Method('findByPk'))
@@ -84,14 +84,14 @@ protected function generateFindAll(): Method
8484
->setPublic()
8585
->setComment('@return ' . $this->entityClassShortName . '[]')
8686
->setReturnType('array')
87-
->setBody('return $this->createEntities($this->findAllCachedInternal());');
87+
->setBody('return $this->_findAllCached();');
8888
}
8989

9090
protected function generateCountAll(): Method
9191
{
9292
return (new Method('countAll'))
9393
->setPublic()
9494
->setReturnType('int')
95-
->setBody('return $this->countAllCachedInternal();');
95+
->setBody('return $this->_countAllCached();');
9696
}
9797
}

src/Generator/TableClassBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ protected function generateFindOne(): ?Method
4545
$this->tableConfig->primaryKeys
4646
);
4747
if (count($this->tableConfig->primaryKeys) === 1) {
48-
$body = 'return $this->createEntity($this->findByPkInternal(' . $this->buildVarsList($this->tableConfig->primaryKeys) . '));';
48+
$body = 'return $this->_findByPk(' . $this->buildVarsList($this->tableConfig->primaryKeys) . ');';
4949
} else {
50-
$body = 'return $this->createEntity($this->findOneInternal(' . $this->buildVarsList($this->tableConfig->primaryKeys) . '));';
50+
$body = 'return $this->_findOne(' . $this->buildVarsList($this->tableConfig->primaryKeys) . ');';
5151
}
5252
$method = (new Method('findByPk'))
5353
->setPublic()
@@ -64,14 +64,14 @@ protected function generateFindAll(): Method
6464
->setPublic()
6565
->setComment('@return ' . $this->entityClassShortName . '[]')
6666
->setReturnType('array')
67-
->setBody('return $this->createEntities($this->findAllInternal());');
67+
->setBody('return $this->_findAll();');
6868
}
6969

7070
protected function generateCountAll(): Method
7171
{
7272
return (new Method('countAll'))
7373
->setPublic()
7474
->setReturnType('int')
75-
->setBody('return $this->countAllInternal();');
75+
->setBody('return $this->_countAll();');
7676
}
7777
}

src/Migration/MigrationVersionTable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ protected function getConfig(): TableConfig
2828

2929
public function checkMigrationExecuted(string $version): bool
3030
{
31-
return (bool)$this->findOneInternal(['version' => $version]);
31+
return (bool)$this->_findOne(['version' => $version]);
3232
}
3333

3434
/**
3535
* @return MigrationVersion[]
3636
*/
3737
public function findAll(): array
3838
{
39-
return $this->createEntities($this->findAllInternal(orderBy: ['executed_at' => 'DESC']));
39+
return $this->_findAll(orderBy: ['executed_at' => 'DESC']);
4040
}
4141

4242
public function insertVersion(AbstractMigration $migration): void
@@ -70,7 +70,7 @@ public function insertVersion(AbstractMigration $migration): void
7070

7171
public function deleteVersion(AbstractMigration $migration): void
7272
{
73-
$entity = $this->createEntity($this->findOneInternal(['version' => $migration->getName()]));
73+
$entity = $this->_findOne(['version' => $migration->getName()]);
7474
$nativeConnection = $this->getConnection()->getNativeConnection();
7575
if ($nativeConnection instanceof \PDO) {
7676
try {

tests/Generator/CachedTableClassBuilderTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function getFlushCacheKeys(TestAutoincrementEntity|AbstractEntity $ent
5656
5757
public function findByPk(int $id): ?TestAutoincrementEntity
5858
{
59-
return $this->createEntity($this->findByPkCachedInternal($id));
59+
return $this->_findByPkCached($id);
6060
}
6161
6262
@@ -65,13 +65,13 @@ public function findByPk(int $id): ?TestAutoincrementEntity
6565
*/
6666
public function findAll(): array
6767
{
68-
return $this->createEntities($this->findAllCachedInternal());
68+
return $this->_findAllCached();
6969
}
7070
7171
7272
public function countAll(): int
7373
{
74-
return $this->countAllCachedInternal();
74+
return $this->_countAllCached();
7575
}
7676
}
7777
'
@@ -105,7 +105,7 @@ protected function getFlushCacheKeys(TestCompositeEntity|AbstractEntity $entity)
105105
106106
public function findByPk(int $user_id, int $post_id): ?TestCompositeEntity
107107
{
108-
return $this->createEntity($this->findOneCachedInternal([\'user_id\' => $user_id, \'post_id\' => $post_id]));
108+
return $this->_findOneCached([\'user_id\' => $user_id, \'post_id\' => $post_id]);
109109
}
110110
111111
@@ -114,13 +114,13 @@ public function findByPk(int $user_id, int $post_id): ?TestCompositeEntity
114114
*/
115115
public function findAll(): array
116116
{
117-
return $this->createEntities($this->findAllCachedInternal());
117+
return $this->_findAllCached();
118118
}
119119
120120
121121
public function countAll(): int
122122
{
123-
return $this->countAllCachedInternal();
123+
return $this->_countAllCached();
124124
}
125125
}
126126
'

tests/Generator/TableClassBuilderTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function getConfig(): TableConfig
4848
4949
public function findByPk(int $id): ?TestAutoincrementEntity
5050
{
51-
return $this->createEntity($this->findByPkInternal($id));
51+
return $this->_findByPk($id);
5252
}
5353
5454
@@ -57,13 +57,13 @@ public function findByPk(int $id): ?TestAutoincrementEntity
5757
*/
5858
public function findAll(): array
5959
{
60-
return $this->createEntities($this->findAllInternal());
60+
return $this->_findAll();
6161
}
6262
6363
6464
public function countAll(): int
6565
{
66-
return $this->countAllInternal();
66+
return $this->_countAll();
6767
}
6868
}
6969
'
@@ -89,7 +89,7 @@ protected function getConfig(): TableConfig
8989
9090
public function findByPk(int $user_id, int $post_id): ?TestCompositeEntity
9191
{
92-
return $this->createEntity($this->findOneInternal([\'user_id\' => $user_id, \'post_id\' => $post_id]));
92+
return $this->_findOne([\'user_id\' => $user_id, \'post_id\' => $post_id]);
9393
}
9494
9595
@@ -98,13 +98,13 @@ public function findByPk(int $user_id, int $post_id): ?TestCompositeEntity
9898
*/
9999
public function findAll(): array
100100
{
101-
return $this->createEntities($this->findAllInternal());
101+
return $this->_findAll();
102102
}
103103
104104
105105
public function countAll(): int
106106
{
107-
return $this->countAllInternal();
107+
return $this->_countAll();
108108
}
109109
}
110110
'

tests/Providers/MySQL/MySQLComparatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public function __construct(
331331
[
332332
'entity' => new Entities\TestOptimisticLockEntity( 'a'),
333333
'sql' => null,
334-
'expectedNewColumns' => ['id', 'name', 'created_at', 'version'],
334+
'expectedNewColumns' => ['id', 'name', 'created_at', 'lock_version'],
335335
'expectedChangedColumns' => [],
336336
'expectedNewIndexes' => [],
337337
'expectedDeletedIndexes' => [],
@@ -342,7 +342,7 @@ public function __construct(
342342
`id` INT NOT NULL AUTO_INCREMENT,
343343
`name` VARCHAR(255) NOT NULL,
344344
`created_at` TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
345-
`version` INT NOT NULL DEFAULT 1,
345+
`lock_version` INT NOT NULL DEFAULT 1,
346346
PRIMARY KEY (`id`)
347347
) ENGINE=InnoDB COLLATE=utf8mb4_unicode_ci;
348348
SQL,

tests/TestStand/Tables/TestMySQLTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ protected function getConfig(): TableConfig
1515

1616
public function findByPk(int $id): ?TestMigrationEntityV1
1717
{
18-
return $this->createEntity($this->findByPkInternal($id));
18+
return $this->_findByPk($id);
1919
}
2020
}

0 commit comments

Comments
 (0)