Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 157 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
"joomla-cypress": "^1.1.1",
"lightningcss": "^1.27.0",
"mysql": "^2.18.1",
"pg": "^8.13.0",
"postcss-scss": "^4.0.9",
"postgres": "^3.4.4",
"recursive-readdir": "^2.2.3",
"rimraf": "^3.0.2",
"rollup": "^2.79.2",
Expand Down
32 changes: 18 additions & 14 deletions tests/System/plugins/db.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import mysql from 'mysql';
import postgres from 'postgres';
import pkg from 'pg';

const { Pool } = pkg; // Using Pool from pg for PostgreSQL connections

// Items cache which are added by an insert statement
let insertedItems = [];

// Use of the PostgreSQL connection pool to limit the number of sessions, see
// https://github.com/porsager/postgres?tab=readme-ov-file#connection-details
// Use of the PostgreSQL connection pool to limit the number of sessions
let postgresConnectionPool = null;

/**
Expand Down Expand Up @@ -37,11 +38,11 @@ function queryTestDB(joomlaQuery, config) {
if (config.env.db_type === 'pgsql' || config.env.db_type === 'PostgreSQL (PDO)') {
if (postgresConnectionPool === null) {
// Initialisation on the first call
postgresConnectionPool = postgres({
postgresConnectionPool = new Pool({
host: config.env.db_host,
port: config.env.db_port,
database: config.env.db_name,
username: config.env.db_user,
user: config.env.db_user,
password: config.env.db_password,
max: 10, // Use only this (unchanged default) maximum number of connections in the pool
});
Expand All @@ -55,24 +56,27 @@ function queryTestDB(joomlaQuery, config) {
// Postgres needs double quotes
query = query.replaceAll('`', '"');

return postgresConnectionPool.unsafe(query).then((result) => {
return postgresConnectionPool.query(query).then((result) => {
// Select query should always return an array
if (query.indexOf('SELECT') === 0 && !Array.isArray(result)) {
return [result];
if (query.startsWith('SELECT') && !Array.isArray(result.rows)) {
return [result.rows];
}

if (!insertItem || result.length === 0) {
return result;
if (!insertItem || result.rows.length === 0) {
return result.rows;
}

// Push the id to the cache when it is an insert operation
if (insertItem && result.length && result[0].id) {
insertItem.rows.push(result[0].id);
if (insertItem && result.rows.length && result.rows[0].id) {
insertItem.rows.push(result.rows[0].id);
}

// Normalize the object and return from PostgreSQL
return { insertId: result[0].id };
});
return { insertId: result.rows[0].id };
})
.catch((error) => {
throw new Error(`Postgres query failed: ${error.message}`);
});
}

// Return a promise which runs the query for MariaDB / MySQL
Expand Down