diff --git a/package-lock.json b/package-lock.json index 954f3c4305b9b..b05b7a176d962 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "joomla", - "version": "5.2.0", + "version": "5.2.1", "hasInstallScript": true, "license": "GPL-2.0-or-later", "dependencies": { @@ -84,8 +84,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", @@ -8813,6 +8813,103 @@ "dev": true, "license": "MIT" }, + "node_modules/pg": { + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/pg/-/pg-8.13.0.tgz", + "integrity": "sha512-34wkUTh3SxTClfoHB3pQ7bIMvw9dpFU1audQQeZG837fmHfHpr14n/AELVDoOYVDW2h5RDWU78tFjkD+erSBsw==", + "dev": true, + "license": "MIT", + "dependencies": { + "pg-connection-string": "^2.7.0", + "pg-pool": "^3.7.0", + "pg-protocol": "^1.7.0", + "pg-types": "^2.1.0", + "pgpass": "1.x" + }, + "engines": { + "node": ">= 8.0.0" + }, + "optionalDependencies": { + "pg-cloudflare": "^1.1.1" + }, + "peerDependencies": { + "pg-native": ">=3.0.1" + }, + "peerDependenciesMeta": { + "pg-native": { + "optional": true + } + } + }, + "node_modules/pg-cloudflare": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.1.1.tgz", + "integrity": "sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==", + "dev": true, + "license": "MIT", + "optional": true + }, + "node_modules/pg-connection-string": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.7.0.tgz", + "integrity": "sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA==", + "dev": true, + "license": "MIT" + }, + "node_modules/pg-int8": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", + "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/pg-pool": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.7.0.tgz", + "integrity": "sha512-ZOBQForurqh4zZWjrgSwwAtzJ7QiRX0ovFkZr2klsen3Nm0aoh33Ls0fzfv3imeH/nw/O27cjdz5kzYJfeGp/g==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "pg": ">=8.0" + } + }, + "node_modules/pg-protocol": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.7.0.tgz", + "integrity": "sha512-hTK/mE36i8fDDhgDFjy6xNOG+LCorxLG3WO17tku+ij6sVHXh1jQUJ8hYAnRhNla4QVD2H8er/FOjc/+EgC6yQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/pg-types": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", + "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", + "dev": true, + "license": "MIT", + "dependencies": { + "pg-int8": "1.0.1", + "postgres-array": "~2.0.0", + "postgres-bytea": "~1.0.0", + "postgres-date": "~1.0.4", + "postgres-interval": "^1.1.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/pgpass": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz", + "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==", + "dev": true, + "license": "MIT", + "dependencies": { + "split2": "^4.1.0" + } + }, "node_modules/picocolors": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.0.tgz", @@ -8969,18 +9066,47 @@ "dev": true, "license": "MIT" }, - "node_modules/postgres": { - "version": "3.4.4", - "resolved": "https://registry.npmjs.org/postgres/-/postgres-3.4.4.tgz", - "integrity": "sha512-IbyN+9KslkqcXa8AO9fxpk97PA4pzewvpi2B3Dwy9u4zpV32QicaEdgmF3eSQUzdRk7ttDHQejNgAEr4XoeH4A==", + "node_modules/postgres-array": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", + "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==", "dev": true, - "license": "Unlicense", + "license": "MIT", "engines": { - "node": ">=12" + "node": ">=4" + } + }, + "node_modules/postgres-bytea": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz", + "integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/postgres-date": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz", + "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/postgres-interval": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz", + "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "xtend": "^4.0.0" }, - "funding": { - "type": "individual", - "url": "https://github.com/sponsors/porsager" + "engines": { + "node": ">=0.10.0" } }, "node_modules/prelude-ls": { @@ -10418,6 +10544,16 @@ "dev": true, "license": "CC0-1.0" }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">= 10.x" + } + }, "node_modules/sqlstring": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz", @@ -11684,6 +11820,16 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.4" + } + }, "node_modules/yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", diff --git a/package.json b/package.json index deb85d697c81e..c32189975d1b5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/System/plugins/db.mjs b/tests/System/plugins/db.mjs index a92065c07e6a5..e24a176ae80e7 100644 --- a/tests/System/plugins/db.mjs +++ b/tests/System/plugins/db.mjs @@ -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; /** @@ -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 }); @@ -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