Page MenuHomeDevCentral

Support PDO PostgreSQL
AcceptedPublic

Authored by dereckson on Thu, Oct 23, 00:41.

Details

Reviewers
dereckson
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
Test Failures
Branch
pdo-postgresql
Build Status
Buildable 6085
Build 6369: 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