-
-
Notifications
You must be signed in to change notification settings - Fork 136
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
Automatic object to Expression conversion #420
Comments
Looking forward to this improvement 👍 |
milo
added a commit
to milo/dibi
that referenced
this issue
Nov 22, 2022
Object translator allows to translate any object passed to Translator into Dibi\Expression.
Closed
milo
added a commit
to milo/dibi
that referenced
this issue
Nov 22, 2022
Object translator allows to translate any object passed to Translator into Dibi\Expression.
milo
added a commit
to milo/dibi
that referenced
this issue
Nov 22, 2022
Object translator allows to translate any object passed to Translator into Dibi\Expression.
milo
added a commit
to milo/dibi
that referenced
this issue
Nov 22, 2022
Object translator allows to translate any object passed to Translator into Dibi\Expression.
milo
added a commit
to milo/dibi
that referenced
this issue
Nov 22, 2022
Object translator allows to translate any object passed to Translator into Dibi\Expression.
milo
added a commit
to milo/dibi
that referenced
this issue
Nov 22, 2022
Object translator allows to translate any object passed to Translator into Dibi\Expression.
milo
added a commit
to milo/dibi
that referenced
this issue
Nov 22, 2022
Object translator allows to translate any object passed to Translator into Dibi\Expression.
milo
added a commit
to milo/dibi
that referenced
this issue
Nov 22, 2022
Object translator allows to translate any object passed to Translator into Dibi\Expression.
milo
added a commit
to milo/dibi
that referenced
this issue
Nov 22, 2022
Object translator allows to translate any object passed to Translator into Dibi\Expression.
milo
added a commit
to milo/dibi
that referenced
this issue
Nov 22, 2022
Object translator allows to translate any object passed to Translator into Dibi\Expression.
milo
added a commit
to milo/dibi
that referenced
this issue
Nov 22, 2022
Object translator allows to translate any object passed to Translator into Dibi\Expression.
dg
pushed a commit
that referenced
this issue
Dec 20, 2022
Object translator allows to translate any object passed to Translator into Dibi\Expression.
milo
added a commit
to milo/dibi
that referenced
this issue
Jan 2, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
dg
pushed a commit
that referenced
this issue
Feb 2, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
dg
pushed a commit
that referenced
this issue
Feb 2, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
I'm closing this issue as a PHP object to Dibi expression is solved by #432 The second case - fetched scalar type to PHP object hydration can be solved by row factory for now and I'm satisfied with that. Maybe I'll open PR for some improvements later. |
dg
pushed a commit
that referenced
this issue
Feb 27, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
Hoping there soon will be a new dibi release with this feature 👍 |
dg
pushed a commit
that referenced
this issue
Aug 5, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
dg
pushed a commit
that referenced
this issue
Aug 5, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
dg
pushed a commit
that referenced
this issue
Aug 5, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
dg
pushed a commit
that referenced
this issue
Aug 5, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
dg
pushed a commit
that referenced
this issue
Aug 5, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
dg
pushed a commit
that referenced
this issue
Aug 9, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
dg
pushed a commit
that referenced
this issue
Aug 9, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
dg
pushed a commit
that referenced
this issue
Aug 9, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
dg
pushed a commit
that referenced
this issue
Aug 9, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
dg
pushed a commit
that referenced
this issue
Aug 9, 2023
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would be nice to have a capability of automatic object to Dibi expression conversion, similar to BackedEnum conversion.
Explanation
Let's start by date and time. Poor PHP support for separated date and time is one of the pain. Basic classes
Date
andTime
are missing, everyting isDateTime
and it is not allowed to implementDateTimeInterface
. As a result, one has to specify data type for data modification in database:The
%d
is always required. And in simple queries the?
modifier can't be used.Next issue is a fetch-and-push-back workflow. Row is fetched from database and cannot be inserted back without modification. I mean:
Inserting back fails, because the value for column
dateOfBirth
is aDateTime
object and it is converted toY-m-d H:i:s
string which is not accepted by database as a value fordate
type.This applies for all value objects. For example, I have custom implementations for
IPv4Address
,IPv4Subnet
, dtto forIPv6...
,EmailAddress
and few more.PHP to SQL
Edit: this part is solved by #432
There was an issue #385 proposing to make
Dibi\Expression
an interface. I proposed to make a new interface with methodtoDibiExpression(): Expression
. I think that both proposes are invalid. A value object should not be aware ofDibi
layer.I propose to create a new interface which will accept object and it will translate it into Dibi expression.
Such translator will be setter-injected into Dibi connection:
And when
Dibi\Translator
hits the object of unknown class, it will callObjectTranslator::translate()
.SQL to PHP
(note: I'm not sure about this part I just want to mention that)
Data type translation of fetched rows now works fine. I think that row factory is sufficient. But there is a space for improvement.
Row fetched from a database layer is a set of scalars and dibi tries to convert them as best as possible. If it does not work for one, type can be set manually:
Maybe this can be extended to
Type::OBJECT
:The
ObjectTranslator
will be extended by another method:Conclusions
It is all about PHP <-> SQL values translations and I think that this solution is clean enough. There are naming questions. Maybe there can be two separate interfaces for PHP -> SQL and SQL -> PHP.
If you think that whole concept is not completely wrong, I'll prepare proof of concept pull request at least for the 1st part, the
PHP to SQL
translation.The text was updated successfully, but these errors were encountered: