Page MenuHomeDevCentral

Support PDO PostgreSQL
ClosedPublic

Authored by dereckson on Thu, Oct 23, 00:41.
Tags
None
Referenced Files
F12329340: D3804.id9853.diff
Fri, Oct 24, 19:01
F12329337: D3804.id9854.diff
Fri, Oct 24, 19:00
Unknown Object (File)
Thu, Oct 23, 12:06
Unknown Object (File)
Thu, Oct 23, 12:06
Unknown Object (File)
Thu, Oct 23, 12:06
Unknown Object (File)
Thu, Oct 23, 08:10
Subscribers
None

Details

Summary

Allow to query PostgreSQL databases through PDO.

Support has been added for both PHP 8.4+ Pdo\Pgsql
and previous versions PDO class.

Use case: Orbeon Forms store data in a PostgreSQL database,
an application for Obsidian Workspaces is planned to read forms
and annotate them into an Obsidian collection.

Test Plan

Unit tests provided for both PDO PostgreSQL engines

Diff Detail

Repository
rKERUALD Keruald libraries development repository
Lint
Lint Warnings
SeverityLocationCodeMessage
Warningdatabase/src/Result/PDODatabaseResult.php:40PHPCS.W.Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileConditionGeneric.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
Unit
Tests Passed
Branch
pdo-postgresql
Build Status
Buildable 6087
Build 6371: arc lint + arc unit

Event Timeline

dereckson created this revision.
database/src/Result/PDODatabaseResult.php
41

Rust loop construct would be handy here.

We could rewrite like this, but I doubt it's easier to read:

while(true) {
    $row = $this->fetchRow();

    if ($row === null) {
        break;
    }

    yield $row;
}

This is strange for the tests:

  • when run with arc unit, tests pass
  • when run from PhpStorm, tests pass
  • when run directly calling phpunit at monorepo root, tests pass
  • when run from databases/ at library root, tests pass

I don't know what arc diff does as race condition, but test restarts both the table AND the sequence from scratch:

BasePDOPostgreSQLTestCase::testNextId
$this->db->query("TRUNCATE numbers RESTART IDENTITY");
$this->db->query("INSERT INTO numbers (id, number) VALUES (1700, 42742)");

If we truncate the table, it should be non-existing.

We could harden the code for a transaction, but I really suspect arc diff to run tests twice in //.

$ phpunit         
Switching to Composer phpunit:
PHPUnit 10.5.58 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.13
Configuration: /datacube/dereckson/dev/nasqueron/keruald/keruald/database/phpunit.xml

................................................................. 65 / 88 ( 73%)
.......................                                           88 / 88 (100%)

Time: 00:03.486, Memory: 4.00 MB

OK (88 tests, 104 assertions)

Transaction so arc diff can run PgsqlPDOEngineTest and PostgreSQLPDOEngineTest in //

This revision is now accepted and ready to land.Thu, Oct 23, 01:00

Bump version and document PostgreSQL drivers in the README

This revision was landed with ongoing or failed builds.Thu, Oct 23, 19:40
This revision was automatically updated to reflect the committed changes.