Switch to using Drupal core pgsql module for database interactions
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3559139. -->
Reported by: [mxr576](https://www.drupal.org/user/315522)
>>>
<h2 id="problem">Problem/Motivation</h2>
<p>
The <code>ai_provider_amazeeio</code> module currently performs database operations with direct calls to the PostgreSQL extension in <code>\Drupal\ai_provider_amazeeio\Vdb\Postgres\PostgresPgvectorClient</code>, bypassing Drupal core's database abstraction layer.
</p>
<ul>
<li>This approach increases maintenance overhead and can make it harder to benefit from Drupal core's database security and compatibility improvements.</li>
<li>Drupal core's <code>pgsql</code> module already provides PostgreSQL PDO bindings and integration with the Database API, which is the recommended way to interact with PostgreSQL from Drupal.</li>
</ul>
<p>
In addition, there is ongoing work in the <code>ai_vdb_provider_postgres</code> project to provide a reusable Postgres-based vector database provider for the Drupal AI ecosystem, which may overlap with the forked Postgres integration in <code>ai_provider_amazeeio</code>.
</p>
<h2 id="proposed-resolution">Proposed resolution</h2>
<h2 id="remaining-tasks">Remaining tasks</h2>
<h2 id="user-impact">User impact</h2>
<ul>
<li>Improved maintainability and security posture of the <code>ai_provider_amazeeio</code> integration by relying on Drupal core's supported database APIs.</li>
<li>Better alignment with Drupal best practices, making it easier for site builders and hosting providers to support and troubleshoot the module.</li>
<li>Potential reduction in duplicated Postgres VDB logic across the Drupal AI ecosystem if common patterns are shared with <code>ai_vdb_provider_postgres</code>, leading to more consistent behavior for end users.</li>
</ul>
<h2 id="related-issues">Related issues</h2>
<ul>
<li><span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-1"><a href="https://www.drupal.org/project/ai_provider_amazeeio/issues/3559138" title="Status: Active">#3559138: Potential collaboration on pgvector VDB support with ai_vdb_provider_postgres</a></span> (discussion about aligning Postgres VDB work and avoiding duplication)</li>
</ul>
> Related issue: [Issue #3547615](https://www.drupal.org/node/3547615)
issue