Compare commits
1 Commits
main
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
812115d505 |
125
package-lock.json
generated
125
package-lock.json
generated
@@ -8,7 +8,7 @@
|
||||
"axios": "^1.11.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^17.2.1",
|
||||
"express": "^5.1.0",
|
||||
"express": "^5.2.0",
|
||||
"mssql": "^11.0.1",
|
||||
"mysql2": "^3.14.3",
|
||||
"oracledb": "^6.9.0",
|
||||
@@ -431,23 +431,43 @@
|
||||
}
|
||||
},
|
||||
"node_modules/body-parser": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.0.tgz",
|
||||
"integrity": "sha512-02qvAaxv8tp7fBa/mw1ga98OGm+eCbqzJOKoRt70sLmfEEi+jyBYVTDGfCL/k06/4EMk/z01gCe7HoCH/f2LTg==",
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.1.tgz",
|
||||
"integrity": "sha512-nfDwkulwiZYQIGwxdy0RUmowMhKcFVcYXUU7m4QlKYim1rUtg83xm2yjZ40QjDuc291AJjjeSc9b++AWHSgSHw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bytes": "^3.1.2",
|
||||
"content-type": "^1.0.5",
|
||||
"debug": "^4.4.0",
|
||||
"debug": "^4.4.3",
|
||||
"http-errors": "^2.0.0",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"iconv-lite": "^0.7.0",
|
||||
"on-finished": "^2.4.1",
|
||||
"qs": "^6.14.0",
|
||||
"raw-body": "^3.0.0",
|
||||
"type-is": "^2.0.0"
|
||||
"raw-body": "^3.0.1",
|
||||
"type-is": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/body-parser/node_modules/iconv-lite": {
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.0.tgz",
|
||||
"integrity": "sha512-cf6L2Ds3h57VVmkZe+Pn+5APsT7FpqJtEhhieDCvrE2MK5Qk9MyffgQyuxQTm6BChfeZNtcOLHp9IcWRVcIcBQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safer-buffer": ">= 2.1.2 < 3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer": {
|
||||
@@ -607,9 +627,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "4.4.1",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz",
|
||||
"integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==",
|
||||
"version": "4.4.3",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
||||
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
@@ -819,18 +839,19 @@
|
||||
}
|
||||
},
|
||||
"node_modules/express": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz",
|
||||
"integrity": "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==",
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/express/-/express-5.2.0.tgz",
|
||||
"integrity": "sha512-XdpJDLxfztVY59X0zPI6sibRiGcxhTPXRD3IhJmjKf2jwMvkRGV1j7loB8U+heeamoU3XvihAaGRTR4aXXUN3A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"accepts": "^2.0.0",
|
||||
"body-parser": "^2.2.0",
|
||||
"body-parser": "^2.2.1",
|
||||
"content-disposition": "^1.0.0",
|
||||
"content-type": "^1.0.5",
|
||||
"cookie": "^0.7.1",
|
||||
"cookie-signature": "^1.2.1",
|
||||
"debug": "^4.4.0",
|
||||
"depd": "^2.0.0",
|
||||
"encodeurl": "^2.0.0",
|
||||
"escape-html": "^1.0.3",
|
||||
"etag": "^1.8.1",
|
||||
@@ -1059,28 +1080,23 @@
|
||||
}
|
||||
},
|
||||
"node_modules/http-errors": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
|
||||
"integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
|
||||
"integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"depd": "2.0.0",
|
||||
"inherits": "2.0.4",
|
||||
"setprototypeof": "1.2.0",
|
||||
"statuses": "2.0.1",
|
||||
"toidentifier": "1.0.1"
|
||||
"depd": "~2.0.0",
|
||||
"inherits": "~2.0.4",
|
||||
"setprototypeof": "~1.2.0",
|
||||
"statuses": "~2.0.2",
|
||||
"toidentifier": "~1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/http-errors/node_modules/statuses": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
|
||||
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/http-proxy-agent": {
|
||||
@@ -1554,6 +1570,7 @@
|
||||
"resolved": "https://registry.npmjs.org/pg/-/pg-8.16.3.tgz",
|
||||
"integrity": "sha512-enxc1h0jA/aq5oSDMvqyW3q89ra6XIIDZgCX9vkMrnz5DFTw/Ny3Li2lFQ+pt3L6MCgm/5o2o8HW9hiJji+xvw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"pg-connection-string": "^2.9.1",
|
||||
"pg-pool": "^3.10.1",
|
||||
@@ -1730,18 +1747,34 @@
|
||||
}
|
||||
},
|
||||
"node_modules/raw-body": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.0.tgz",
|
||||
"integrity": "sha512-RmkhL8CAyCRPXCE28MMH0z2PNWQBNk2Q09ZdxM9IOOXwxwZbN+qbWaatPkdkWIKL2ZVDImrN/pK5HTRz2PcS4g==",
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz",
|
||||
"integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bytes": "3.1.2",
|
||||
"http-errors": "2.0.0",
|
||||
"iconv-lite": "0.6.3",
|
||||
"unpipe": "1.0.0"
|
||||
"bytes": "~3.1.2",
|
||||
"http-errors": "~2.0.1",
|
||||
"iconv-lite": "~0.7.0",
|
||||
"unpipe": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/raw-body/node_modules/iconv-lite": {
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.0.tgz",
|
||||
"integrity": "sha512-cf6L2Ds3h57VVmkZe+Pn+5APsT7FpqJtEhhieDCvrE2MK5Qk9MyffgQyuxQTm6BChfeZNtcOLHp9IcWRVcIcBQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safer-buffer": ">= 2.1.2 < 3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/readable-stream": {
|
||||
@@ -2084,15 +2117,19 @@
|
||||
}
|
||||
},
|
||||
"node_modules/type-is/node_modules/mime-types": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.1.tgz",
|
||||
"integrity": "sha512-xRc4oEhT6eaBpU1XF7AjpOFD+xQmXNB5OVKwp4tqCuBpHLS/ZbBDrc07mYTDqVMg6PfxUjjNp85O6Cd2Z/5HWA==",
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz",
|
||||
"integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mime-db": "^1.54.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/express"
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"axios": "^1.11.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^17.2.1",
|
||||
"express": "^5.1.0",
|
||||
"express": "^5.2.0",
|
||||
"mssql": "^11.0.1",
|
||||
"mysql2": "^3.14.3",
|
||||
"oracledb": "^6.9.0",
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
require('dotenv').config();
|
||||
const sql = require('mssql');
|
||||
const oracledb = require('oracledb');
|
||||
const mysql = require('mysql2/promise');
|
||||
const { Client } = require('pg');
|
||||
|
||||
/**
|
||||
* Gets a connection based on the configured database type.
|
||||
@@ -16,8 +18,14 @@ async function getConnection() {
|
||||
switch (dbType) {
|
||||
case 'MSSQL':
|
||||
return await sql.connect(config);
|
||||
case 'ORACLE':
|
||||
return await oracledb.getConnection(config);
|
||||
case 'MARIADB':
|
||||
return await mysql.createConnection(config);
|
||||
case 'POSTGRES':
|
||||
const client = new Client(config);
|
||||
await client.connect();
|
||||
return client;
|
||||
default:
|
||||
throw new Error('Unsupported database type');
|
||||
}
|
||||
@@ -42,6 +50,12 @@ function getDBConfig(dbType) {
|
||||
trustServerCertificate: true
|
||||
}
|
||||
};
|
||||
case 'ORACLE':
|
||||
return {
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
connectString: process.env.ORACLE_CONNECTION_STRING
|
||||
};
|
||||
case 'MARIADB':
|
||||
return {
|
||||
host: process.env.DB_SERVER,
|
||||
@@ -51,6 +65,14 @@ function getDBConfig(dbType) {
|
||||
database: process.env.DB_DATABASE,
|
||||
namedPlaceholders: true
|
||||
};
|
||||
case 'POSTGRES':
|
||||
return {
|
||||
host: process.env.DB_SERVER,
|
||||
port: parseInt(process.env.DB_PORT, 10) || 5432,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_DATABASE
|
||||
};
|
||||
default:
|
||||
throw new Error('Unsupported database type');
|
||||
}
|
||||
|
||||
@@ -28,11 +28,15 @@ async function formatQueryParams(params) {
|
||||
case 'MSSQL':
|
||||
formattedParams = formatMSSQLParams(params, paramsConfig.mssql);
|
||||
break;
|
||||
|
||||
case 'ORACLE':
|
||||
formattedParams = formatOracleParams(params, paramsConfig.oracle);
|
||||
break;
|
||||
case 'MARIADB':
|
||||
formattedParams = formatMariaDBParams(params, paramsConfig.mariaDB);
|
||||
break;
|
||||
|
||||
case 'POSTGRES':
|
||||
formattedParams = formatPostgresParams(params, paramsConfig.postgres);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unsupported database type');
|
||||
}
|
||||
@@ -87,6 +91,51 @@ function formatMSSQLParams(params, config) {
|
||||
return formattedParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats query parameters for Oracle.
|
||||
*
|
||||
* @param {Object} params - An object containing the parameters to format.
|
||||
* @param {Object} config - Database-specific configuration from JSON.
|
||||
* @returns {Object} Formatted parameters.
|
||||
*/
|
||||
function formatOracleParams(params, config) {
|
||||
const formattedParams = {};
|
||||
for (const key in params) {
|
||||
if (!config[key]) {
|
||||
console.warn(`Parameter '${key}' not defined in the configuration.`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const paramConfig = config[key];
|
||||
let type;
|
||||
|
||||
switch (paramConfig.type.toLowerCase()) {
|
||||
case 'string':
|
||||
type = oracledb.STRING;
|
||||
break;
|
||||
case 'varchar2':
|
||||
if (!paramConfig.maxLength) {
|
||||
throw new Error(`Parameter '${key}' is missing maxLength in configuration.`);
|
||||
}
|
||||
type = oracledb.VARCHAR2(paramConfig.maxLength);
|
||||
break;
|
||||
case 'clob':
|
||||
type = oracledb.CLOB;
|
||||
break;
|
||||
case 'number':
|
||||
type = oracledb.NUMBER;
|
||||
break;
|
||||
case 'boolean':
|
||||
type = oracledb.BOOLEAN;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported parameter type: ${paramConfig.type} for parameter '${key}'`);
|
||||
}
|
||||
|
||||
formattedParams[key] = { type, value: params[key] };
|
||||
}
|
||||
return formattedParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats query parameters for MariaDB.
|
||||
@@ -137,5 +186,51 @@ function formatMariaDBParams(params, config) {
|
||||
return formattedParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats query parameters for PostgreSQL.
|
||||
*
|
||||
* @param {Object} params - An object containing the parameters to format.
|
||||
* @param {Object} config - Database-specific configuration from JSON.
|
||||
* @returns {Object} Formatted parameters.
|
||||
*/
|
||||
function formatPostgresParams(params, config) {
|
||||
const formattedParams = {};
|
||||
for (const key in params) {
|
||||
if (!config[key]) {
|
||||
console.warn(`Parameter '${key}' not defined in the configuration.`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const paramConfig = config[key];
|
||||
let type;
|
||||
|
||||
switch (paramConfig.type.toLowerCase()) {
|
||||
case 'uuid':
|
||||
type = 'uuid';
|
||||
break;
|
||||
case 'varchar':
|
||||
if (!paramConfig.length) {
|
||||
throw new Error(`Parameter '${key}' is missing length in configuration.`);
|
||||
}
|
||||
type = { type: 'VARCHAR', length: paramConfig.length };
|
||||
break;
|
||||
case 'text':
|
||||
type = 'text';
|
||||
break;
|
||||
case 'int':
|
||||
type = 'int';
|
||||
break;
|
||||
case 'boolean':
|
||||
type = 'boolean';
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported parameter type: ${paramConfig.type} for parameter '${key}'`);
|
||||
}
|
||||
|
||||
formattedParams[key] = { type, value: params[key] };
|
||||
}
|
||||
return formattedParams;
|
||||
}
|
||||
|
||||
module.exports = { formatQueryParams };
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
"Name": { "type": "nvarchar", "maxLength": 255 },
|
||||
"Description": { "type": "nvarchar", "maxLength": 255 },
|
||||
"Building": { "type": "nvarchar", "maxLength": 255 },
|
||||
"Bin": { "type": "nvarchar", "maxLength": 255 },
|
||||
"Owner": { "type": "nvarchar", "maxLength": 255 },
|
||||
"Role": { "type": "nvarchar", "maxLength": 255 },
|
||||
"Location": { "type": "nvarchar", "maxLength": 255 },
|
||||
@@ -15,14 +14,34 @@
|
||||
"Username": { "type": "nvarchar", "maxLength": 50 },
|
||||
"AuthenticatedUsername": { "type": "nvarchar", "maxLength": 50 },
|
||||
"UITheme": { "type": "nvarchar", "maxLength": 50 },
|
||||
"Bio": { "type": "nvarchar", "maxlength": 255 },
|
||||
"Bio": { "type": "text" },
|
||||
"PasswordHash": { "type": "text" },
|
||||
"Image": { "type": "nvarchar", "maxLength": 255 },
|
||||
"AvatarURL": { "type": "nvarchar", "maxlength": 255 },
|
||||
"Image": { "type": "text" },
|
||||
"AvatarURL": { "type": "text" },
|
||||
"SQL_USER": { "type": "bit" },
|
||||
"Text": { "type": "nvarchar", "maxLength": 255 },
|
||||
"Quantity": { "type": "int" },
|
||||
"RequestPayload": { "type": "text" }
|
||||
"Text": { "type": "nvarchar", "maxLength": 255 }
|
||||
},
|
||||
"oracle": {
|
||||
"ID": { "type": "string" },
|
||||
"Name": { "type": "varchar2", "maxLength": 255 },
|
||||
"Description": { "type": "varchar2", "maxLength": 255 },
|
||||
"Text": { "type": "varchar2", "maxLength": 255 },
|
||||
"Building": { "type": "varchar2", "maxLength": 255 },
|
||||
"Owner": { "type": "varchar2", "maxLength": 255 },
|
||||
"Role": { "type": "varchar2", "maxLength": 255 },
|
||||
"Location": { "type": "varchar2", "maxLength": 255 },
|
||||
"Route": { "type": "varchar2", "maxLength": 255 },
|
||||
"Email": { "type": "varchar2", "maxLength": 255 },
|
||||
"DisplayName": { "type": "varchar2", "maxLength": 255 },
|
||||
"Team": { "type": "varchar2", "maxLength": 255 },
|
||||
"Username": { "type": "varchar2", "maxLength": 50 },
|
||||
"AuthenticatedUsername": { "type": "varchar2", "maxLength": 50 },
|
||||
"UITheme": { "type": "varchar2", "maxLength": 50 },
|
||||
"Bio": { "type": "clob" },
|
||||
"PasswordHash": { "type": "clob" },
|
||||
"Image": { "type": "clob" },
|
||||
"AvatarURL": { "type": "clob" },
|
||||
"SQL_USER": { "type": "boolean" }
|
||||
},
|
||||
"mariaDB": {
|
||||
"ID": { "type": "uuid" },
|
||||
@@ -45,5 +64,27 @@
|
||||
"Image": { "type": "text" },
|
||||
"AvatarURL": { "type": "text" },
|
||||
"SQL_USER": { "type": "boolean" }
|
||||
},
|
||||
"postgres": {
|
||||
"ID": { "type": "uuid" },
|
||||
"Name": { "type": "varchar", "length": 255 },
|
||||
"Description": { "type": "varchar", "length": 255 },
|
||||
"Text": { "type": "varchar", "length": 255 },
|
||||
"Building": { "type": "varchar", "length": 255 },
|
||||
"Owner": { "type": "varchar", "length": 255 },
|
||||
"Role": { "type": "varchar", "length": 255 },
|
||||
"Location": { "type": "varchar", "length": 255 },
|
||||
"Route": { "type": "varchar", "length": 255 },
|
||||
"Email": { "type": "varchar", "length": 255 },
|
||||
"DisplayName": { "type": "varchar", "length": 255 },
|
||||
"Team": { "type": "varchar", "length": 255 },
|
||||
"Username": { "type": "varchar", "length": 50 },
|
||||
"AuthenticatedUsername": { "type": "varchar", "length": 50 },
|
||||
"UITheme": { "type": "varchar", "length": 50 },
|
||||
"Bio": { "type": "text" },
|
||||
"PasswordHash": { "type": "text" },
|
||||
"Image": { "type": "text" },
|
||||
"AvatarURL": { "type": "text" },
|
||||
"SQL_USER": { "type": "boolean" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,9 +117,14 @@ function generateCreateQuery(dbType, table, params) {
|
||||
.map(key => `@${key}`)
|
||||
.join(', ');
|
||||
break;
|
||||
case 'POSTGRES':
|
||||
placeholders = Object.keys(params).map(() => '?').join(', '); // Use ? for PostgreSQL
|
||||
break;
|
||||
case 'MARIADB':
|
||||
placeholders = Object.keys(params).map(() => `?`).join(', '); // Use ? for MariaDB
|
||||
break;
|
||||
case 'ORACLE':
|
||||
throw new Error('CREATE operation is not supported for ORACLE in this implementation.');
|
||||
default:
|
||||
throw new Error('Unsupported database type for this operation!');
|
||||
}
|
||||
@@ -156,6 +161,22 @@ function generateReadQuery(dbType, table, params) {
|
||||
condition = `${key} = @${key}`;
|
||||
}
|
||||
break;
|
||||
case 'ORACLE':
|
||||
if (params.partialMatch) {
|
||||
condition = `${key} LIKE '%' || :${key} || '%'`;
|
||||
params[key] = `%${params[key]}%`; // Add % wildcard in params
|
||||
} else {
|
||||
condition = `${key} = :${key}`;
|
||||
}
|
||||
break;
|
||||
case 'POSTGRES':
|
||||
if (params.partialMatch) {
|
||||
condition = `${key} LIKE $1`;
|
||||
params[key] = `%${params[key]}%`; // Add % wildcard in params
|
||||
} else {
|
||||
condition = `${key} = $1`;
|
||||
}
|
||||
break;
|
||||
case 'MARIADB':
|
||||
if (params.partialMatch) {
|
||||
condition = `${key} LIKE ?`;
|
||||
@@ -210,6 +231,9 @@ async function generateUpdateQuery(dbType, table, params) {
|
||||
case 'MSSQL':
|
||||
whereClause = `WHERE ID = @ID`;
|
||||
break;
|
||||
case 'POSTGRES':
|
||||
whereClause = `WHERE ID = $2`;
|
||||
break;
|
||||
case 'MARIADB':
|
||||
whereClause = `WHERE ID = ?`;
|
||||
break;
|
||||
@@ -234,8 +258,12 @@ async function generateDeleteQuery(dbType, table, params) {
|
||||
switch (dbType.toUpperCase()) {
|
||||
case 'MSSQL':
|
||||
return `DELETE FROM ${table} WHERE ID = @ID;`;
|
||||
case 'POSTGRES':
|
||||
return `DELETE FROM ${table} WHERE ID = $1;`; // Use $1 for PostgreSQL
|
||||
case 'MARIADB':
|
||||
return `DELETE FROM ${table} WHERE ID = ?;`;
|
||||
case 'ORACLE':
|
||||
throw new Error('DELETE operation is not supported for ORACLE in this implementation.');
|
||||
default:
|
||||
throw new Error('Unsupported database type!');
|
||||
}
|
||||
@@ -251,10 +279,57 @@ async function generateTestQuery(dbType) {
|
||||
switch (dbType.toUpperCase()) {
|
||||
case 'MSSQL':
|
||||
return `SELECT @@SPID;`;
|
||||
case 'POSTGRES':
|
||||
return `SELECT pg_backend_pid();`; // Use $1 for PostgreSQL
|
||||
case 'MARIADB':
|
||||
return `SELECT CONNECTION_ID();`;
|
||||
case 'ORACLE':
|
||||
return `SELECT SYS_CONTEXT('USERENV', 'SESSIONID') FROM dual;`;
|
||||
default:
|
||||
throw new Error('Unsupported database type!');
|
||||
}
|
||||
}
|
||||
/*
|
||||
*
|
||||
* I intend to implement "compare" functionality but haven't yet decided how to do so. This is some spitballed code that I came up with for this exercise, and I hope to complete work on it in the future.
|
||||
/**
|
||||
* Generates a COMPARE SQL query string based on database type, table, and parameters.
|
||||
*
|
||||
* @param {string} dbType - Type of database (e.g., 'MSSQL', 'ORACLE').
|
||||
* @param {Object} params - Parameters for the SQL query.
|
||||
* @returns {string} The constructed COMPARE SQL query string.
|
||||
*
|
||||
function generateCompareQuery(dbType, table, params) {
|
||||
const { compareTable, idField } = params;
|
||||
|
||||
switch (dbType.toUpperCase()) {
|
||||
case 'MSSQL':
|
||||
return `
|
||||
SELECT a.*
|
||||
FROM ${table} a
|
||||
JOIN ${compareTable} b ON a.${idField} = b.${idField}
|
||||
`;
|
||||
case 'ORACLE':
|
||||
return `
|
||||
SELECT a.*
|
||||
FROM ${table} a
|
||||
JOIN ${compareTable} b ON a.${idField} = b.${idField}
|
||||
`;
|
||||
case 'POSTGRES':
|
||||
return `
|
||||
SELECT a.*
|
||||
FROM ${table} a
|
||||
JOIN ${compareTable} b ON a.${idField} = b.${idField}
|
||||
`;
|
||||
case 'MARIADB':
|
||||
return `
|
||||
SELECT a.*
|
||||
FROM ${table} a
|
||||
JOIN ${compareTable} b ON a.${idField} = b.${idField}
|
||||
`;
|
||||
default:
|
||||
throw new Error('Unsupported database type');
|
||||
}
|
||||
}*/
|
||||
|
||||
module.exports = { generateQuery };
|
||||
|
||||
@@ -32,11 +32,21 @@ async function executeQuery(table, operation, params) {
|
||||
console.log('Formatted parameters for MSSQL:', formattedParams); // Log the formatted parameters
|
||||
result = await executeMSSQLQuery(connection, query, formattedParams);
|
||||
break;
|
||||
case 'ORACLE':
|
||||
console.log('Executing Oracle query:', query); // Debugging log
|
||||
console.log('Formatted parameters for Oracle:', formattedParams); // Log the formatted parameters
|
||||
result = await executeOracleQuery(connection, query, formattedParams);
|
||||
break;
|
||||
case 'MARIADB':
|
||||
console.log('Executing MariaDB query:', query); // Debugging log
|
||||
console.log('Formatted parameters for MariaDB:', formattedParams); // Log the formatted parameters
|
||||
result = await executeMariaDBQuery(connection, query, formattedParams);
|
||||
break;
|
||||
case 'POSTGRES':
|
||||
console.log('Executing PostgreSQL query:', query); // Debugging log
|
||||
console.log('Formatted parameters for PostgreSQL:', formattedParams); // Log the formatted parameters
|
||||
result = await executePostgresQuery(connection, query, formattedParams);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unsupported database type');
|
||||
}
|
||||
@@ -81,6 +91,30 @@ async function executeMSSQLQuery(connection, query, params) {
|
||||
}
|
||||
}
|
||||
|
||||
async function executeOracleQuery(connection, query, params) {
|
||||
const binds = {};
|
||||
|
||||
// Bind each parameter with its name and value
|
||||
Object.keys(params).forEach((key, index) => {
|
||||
binds[`param${index + 1}`] = { type: params[key].type, val: params[key].value };
|
||||
});
|
||||
|
||||
const options = {
|
||||
outFormat: require('oracledb').OUT_FORMAT_OBJECT
|
||||
};
|
||||
|
||||
try {
|
||||
console.log('Executing Oracle query:', query); // Debugging log
|
||||
console.log('Binding parameters for Oracle:', binds); // Debugging log
|
||||
const result = await connection.execute(query, binds, options);
|
||||
return { recordset: result.rows, affectedRows: result.rowsAffected };
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error executing Oracle query:', error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function executeMariaDBQuery(connection, query, params) {
|
||||
try {
|
||||
// Extract parameter values in order
|
||||
@@ -96,4 +130,20 @@ async function executeMariaDBQuery(connection, query, params) {
|
||||
}
|
||||
}
|
||||
|
||||
async function executePostgresQuery(connection, query, params) {
|
||||
try {
|
||||
// Extract parameter values in order
|
||||
const paramValues = Object.keys(params).map(key => params[key].value);
|
||||
|
||||
console.log('Executing PostgreSQL query:', query); // Debugging log
|
||||
console.log('Binding parameters for PostgreSQL:', paramValues); // Debugging log
|
||||
|
||||
const result = await connection.query(query, paramValues);
|
||||
return { recordset: result.rows };
|
||||
} catch (error) {
|
||||
console.error('Error executing PostgreSQL query:', error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { executeQuery };
|
||||
Reference in New Issue
Block a user