feat(entity): Provide a new API for entities - #56199
Conversation
|
Would have preferred the new API and the reference implementation in backup codes and Tagging to be two different commits. But cool. What do you think of a CacheEnabled repository next to it (that wraps the Repository and just has a runtime cache)? Have a mapper with such functionality in tables, and saw it on at least another app as well, might be worth to have something like this implemented once properly? |
Currently it's more of a prototype, I'll split that in multiple commits.
Yes that could make sense. That I also saw in multiple apps is the relation stuff: https://github.com/nextcloud/deck/blob/main/lib/Db/RelationalEntity.php which could be quite handy |
27d1fd8 to
29a9903
Compare
29a9903 to
0ac62ed
Compare
f362314 to
68c1790
Compare
| protected readonly IDBConnection $connection, | ||
| protected readonly string $entityClass, | ||
| ) { | ||
| $this->entityManager = Server::get(EntityManager::class); |
There was a problem hiding this comment.
Please document why no DI (loop I suppose?)
There was a problem hiding this comment.
Mostly because EntityManager is a private API (for now at least) and so it makes it possible to create a Repository without depending on it
There was a problem hiding this comment.
Ah yeah, because child classes call the parent constructor so it needs public API only in its parameters.
If we put the entity class into a const that child classes override or something like that we may avoid the need for a constructor in most child classes, but I guess that won’t always work, some may want a constructor anyway. Not sure what the pretty solution is.
There was a problem hiding this comment.
I now use a const and made the constructor internal
come-nc
left a comment
There was a problem hiding this comment.
How is the modified columns detection replaced?
I think the old API was keeping track of which values were modified and I did not see how it is done here, as properties are public and set directly.
There is no detection, all properties are updated all the time. IHMO this is negligible in term of performance/network compared to the effort required to track changes via something similar to Doctrine Unit of Work as there isn't super frequent updates and for high performance code, it's best to anyway write queries manually requesting only what is needed and writing only what changed. See https://www.doctrine-project.org/projects/doctrine-orm/en/3.6/reference/unitofwork.html At the moment, since the public API is minimal, we could add support for that later on. |
Entity are now simple data object with attributes for the database mapping. They are manipulated via a Repository which reads the attributes to insert, update, delete and queries the PDO from the database. Using attributes makes it easier to extends in the future with relations (ManyToMany, OneToMany, OneToOne, ...). The design of the Repository is based on a mix between the Doctrine ORM repository while keeping some methods from the QBMapper for easier porting. Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
And do a lot of refactoring Signed-off-by: Carl Schwan <carlschwan@kde.org>
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Assisted-by: ClaudeCode:claude-opus-4-8 Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
This is a left over from the maps prototype Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1fe06c7 to
5e9186a
Compare
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
5e9186a to
3584712
Compare
Let's keep this for a later refactor Signed-off-by: Carl Schwan <carl@carlschwan.eu>
77140cf to
476c196
Compare
ChristophWurst
left a comment
There was a problem hiding this comment.
Quick review
Good stuff 👏
| use OCP\Snowflake\ISnowflakeGenerator; | ||
|
|
||
| /** | ||
| * Attribute for marking a column as a primary id. |
There was a problem hiding this comment.
It is a rare case, but do we want to allow composite primary keys? Example would be an n:m mapping table. It could just use the two foreign keys as primary key. If we enforce a single primary key column then it needs a third column.
There was a problem hiding this comment.
good point, doctrine does support this: https://www.doctrine-project.org/projects/doctrine-orm/en/3.6/tutorials/composite-primary-keys.html#primitive-types-only
So let's see if I can drop the requirement of only one Id attribute
Entity are now simple data object with attributes for the database mapping. They are manipulated via a Repository which reads the attributes to insert, update, delete and queries the PDO from the database.
Using attributes makes it easier to extends in the future with relations (ManyToMany, OneToMany, OneToOne, ...).
The design of the Repository is based on a mix between the Doctrine ORM repository while keeping some methods from the QBMapper for easier porting.
Example of a entity
Supported
Missing but for later
Checklist
3. to review, feature component)stable32)