-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #39 - Adds MySQL TIMESTAMP and PgSQL DATETIME formats. #40
Conversation
The performance is based on how soon we find the right format, so we want to prefer more common formats (like database formats) over less-common formats. Also refactoring the tests to use more consistent language around database types.
Thank you very much for the contribution!
You don't rely on an ORM and do the hydration of your value objects yourself? I'm just a bit curious about how you use the library. Happy it helps though. 🙂 |
Typically I build my own domain model rather than using an ORM. The logic is pretty straightforward and very easy to test. In this case, I would be populating value and entity objects from raw data pulled from the database. Sample code: public function findUserByEmail(string $email) : ?User
{
$select = $this->queryFactory->newSelect();
$select->cols(['*'])->from('user_account')->where('email = :email');
$result = $this->pdo->fetchOne($select, ['email' => $email]);
if (!$result) {
return null;
}
if ($result['last_login']) {
$result['last_login'] = [
'datetime' => $result['last_login'],
'format' => 'Y-m-d H:i:s.u',
];
}
return (new MapperBuilder())->mapper()->map(
User::class,
$result
);
} |
I see; I am also trying out DDD with a customer, but we still use Doctrine's ORM although we already thought about not using it at all (at least for read-models); we'll maybe reconsider this option. Thanks again for the contribution. 🙂 |
Domain model has nothing to do with the usage of an ORM or not. The Domain Model is the ensemble of all entities that fit your business requirements. Then, you have several ways to bind it with your persistence layer (database): you can use an ORM to do the work automatically or hydrate objects by yourself. Notice that you still use a kind of ORM (in you example code), by requiring a "mapper" to build your object (an ORM being somehow a "mapper"). So what's the point to replace Doctrine ORM with this custom MapperBuilder? If the point to drop Doctrine ORM was performance, you should know that it's generally caused by a poor usage of the ORM rather than the ORM itself. You can, for example, use the Some useful links: |
$mysqlDate = '2012-12-21 13:37:42'; | ||
$pgsqlDate = '2012-12-21 13:37:42.123456'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm honestly wondering whether this test with these data is any useful. The current mapper's implementation is brute-forcing through various formats, using the first one that works.
The mechanism itself may be fine, though in this test each and every use-case is testing against the very same date time, potentially allowing/hiding false-positives where one format succeeds over the one that was supposed to be tested.
My proposal here would be to change each test-case to a different datetime to ensure that each test is actually doing what it's supposed to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good advice, thank you for the review.
I'm not sure I put these in the right place, but if there's a better place, let me know.
I see this package being incredibly useful for automatically mapping data from databases into entities/value objects, so I hope that you'll consider this patch.