-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add the PgSQL driver #5880
Add the PgSQL driver #5880
Conversation
e15288c
to
98a3d9d
Compare
@@ -19,7 +19,6 @@ | |||
<file name="vendor/jetbrains/phpstorm-stubs/ibm_db2/ibm_db2.php" /> | |||
<file name="vendor/jetbrains/phpstorm-stubs/mysqli/mysqli.php" /> | |||
<file name="vendor/jetbrains/phpstorm-stubs/oci8/oci8.php" /> | |||
<file name="vendor/jetbrains/phpstorm-stubs/pgsql/pgsql.php" /> |
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.
Psalm actually runs better using its own ext-pgsql
stubs. 🧐
3703622
to
099c454
Compare
292ad2c
to
ea1118f
Compare
Running the ORM test suite uncovered a nice little bug in the type mapping logic. 😓 On it. |
ea1118f
to
06f853e
Compare
I've added The ORM's test suite passes now, but it's significantly slower with the new driver than it is with PDO. 😕 But I can investigate this in a follow-up, I guess. |
06f853e
to
a9de161
Compare
59df42d
to
9683fcd
Compare
Should we somehow document the new driver as experimental because of this? |
9683fcd
to
319b3d4
Compare
319b3d4
to
4c06a52
Compare
Done. |
It may be related to "real" prepared statements, in comparison to emulated prepared statements in PDO. |
You mean because those real prepared statements mean an extra round-trip to the Posgres server? But that is nevertheless desirable, isn't it? I'm not sure I want to resolve prepared statements in the driver. 🙈 |
Summary
This PR introduces a new Postgres driver that leverages PHP's
pgsql
extension. Postgres is currently the last database that we only support through PDO. This driver closes the gap.ext-pgsql
has a rather verbose API. Unlike other database extensions, it does not even bother to cast result types: It returns everything as a string. Except fornull
values: Those are reallynull
!However, we get information on the database type of all result fields, so we are able to perform those casts ourselves. This is why I decided to perform very basic type mappings in the driver already. Otherwise, the result sets produced by
ext-pgsql
would have been a permanent edge case: Booleans come as't'
and'f'
, binary data is returned as hex string prefixed with0x
. Not casting those would cause a lot of functional tests to fail.The type casts that I perform in the driver should be similar to what
PDO_pgsql
does internally as well. That should make a potential switch from PDO to the native extension rather seamless.In PHP 8.1, all resource types used by the extensions have been changed to objects. This is why you will see a couple of type annotations with a union of
resource
and some class from thePgSql
namespace. This PR currently targets DBAL 3.6 and PHP 7.4. Once this code hits the 4.x branch, we can simplify a lot of type declarations.The one big limitation though is that I haven't implemented support for loading BLOBs from resources yet. That topic is a bit complex, so I'd like to work on that in a follow-up. For now, I think we can ship this driver without BLOB support.