froth-webdriverio-framework 1.0.93 → 1.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/db/postgresOperations.js +29 -27
- package/package.json +2 -1
package/db/postgresOperations.js
CHANGED
|
@@ -1,39 +1,43 @@
|
|
|
1
1
|
const { Pool } = require('pg');
|
|
2
2
|
|
|
3
|
-
// Function to establish connection to
|
|
3
|
+
// Function to establish connection to MySQL database
|
|
4
4
|
async function connectToPostgreSQL(hostname, username, password, dbname, portnumber) {
|
|
5
|
-
const poolConfig = {
|
|
6
|
-
host: hostname,
|
|
7
|
-
user: username,
|
|
8
|
-
password: password,
|
|
9
|
-
database: dbname,
|
|
10
|
-
port: portnumber,
|
|
11
|
-
max: 10,
|
|
12
|
-
idleTimeoutMillis: 60000,
|
|
13
|
-
connectionTimeoutMillis: 60000,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
5
|
try {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
const poolConfig = new Pool({
|
|
7
|
+
user: username,
|
|
8
|
+
host: hostname,
|
|
9
|
+
database: dbname,
|
|
10
|
+
password: password,
|
|
11
|
+
port: 5432,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const client = await poolConfig.connect();
|
|
16
|
+
console.log('Connected to the database');
|
|
17
|
+
// Optionally, run a simple query to verify the connection
|
|
18
|
+
const res = await client.query('SELECT NOW()');
|
|
19
|
+
console.log("postgresresults "+res.rows[0]);
|
|
20
|
+
client.release();
|
|
21
|
+
|
|
20
22
|
} catch (error) {
|
|
21
|
-
console.error('Error creating
|
|
23
|
+
console.error('Error creating MySQL connection pool:', error);
|
|
22
24
|
throw error;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
|
|
26
29
|
// Function to fetch data from the database
|
|
27
|
-
async function
|
|
30
|
+
async function fetchDataFromDB(connectionpool, query) {
|
|
28
31
|
let connection = null;
|
|
29
32
|
let finalResult = null;
|
|
30
33
|
try {
|
|
34
|
+
console.log("connectionpool" + connectionpool)
|
|
35
|
+
connection = await connectionpool.getConnection();
|
|
31
36
|
|
|
32
|
-
|
|
33
|
-
console.log('Connected to the PostgreSQL database.' + connection);
|
|
34
|
-
const result = await connection.query(query);
|
|
35
|
-
const dataArray = result.rows; // Adjust for MySQL and PostgreSQL response formats
|
|
37
|
+
console.log('Connected to the MySQL database.' + connection);
|
|
36
38
|
|
|
39
|
+
const [rows] = await connection.execute(query);
|
|
40
|
+
const dataArray = rows;
|
|
37
41
|
finalResult = {
|
|
38
42
|
totalNumberOfRecords: dataArray.length,
|
|
39
43
|
records: dataArray
|
|
@@ -43,9 +47,7 @@ async function fetchDataFromPostgresDB(connectionpool, query) {
|
|
|
43
47
|
console.error('Error fetching data:', error);
|
|
44
48
|
} finally {
|
|
45
49
|
if (connection) {
|
|
46
|
-
|
|
47
50
|
connection.release();
|
|
48
|
-
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
return finalResult;
|
|
@@ -54,10 +56,10 @@ async function fetchDataFromPostgresDB(connectionpool, query) {
|
|
|
54
56
|
// Main function to call the database connection and fetch data
|
|
55
57
|
// async function main() {
|
|
56
58
|
// try {
|
|
57
|
-
// const connection = await
|
|
59
|
+
// const connection = await connectToMySQL('10.0.0.6', 'root', 'password123', 'power_seraya_step', 3406);
|
|
58
60
|
// console.log('Connection pool created.' + connection);
|
|
59
|
-
// const query = 'SELECT
|
|
60
|
-
// await
|
|
61
|
+
// const query = 'SELECT id,EventID,NoPlate FROM store_images limit 2';
|
|
62
|
+
// await fetchDataFromDB(connection, query);
|
|
61
63
|
// } catch (err) {
|
|
62
64
|
// console.log('Error connecting to database:', err.stack);
|
|
63
65
|
// }
|
|
@@ -67,5 +69,5 @@ async function fetchDataFromPostgresDB(connectionpool, query) {
|
|
|
67
69
|
|
|
68
70
|
module.exports = {
|
|
69
71
|
connectToPostgreSQL,
|
|
70
|
-
|
|
72
|
+
fetchDataFromDB
|
|
71
73
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "froth-webdriverio-framework",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.95",
|
|
4
4
|
"readme": "WebdriverIO Integration",
|
|
5
5
|
"description": "WebdriverIO and BrowserStack App Automate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"node-fetch": "^3.3.2",
|
|
41
41
|
"node-localstorage": "^3.0.5",
|
|
42
42
|
"pg": "^8.12.0",
|
|
43
|
+
"pg-promise": "^11.9.0",
|
|
43
44
|
"ts-node": "^10.9.2",
|
|
44
45
|
"typescript": "^5.4.5"
|
|
45
46
|
}
|