estatesfunding/ef-api/db/db.js

27 lines
819 B
JavaScript
Raw Normal View History

2024-09-20 11:18:56 +00:00
import mysql from "mysql2/promise"; // Use promise-based API
// Create a pool instead of a single connection
const pool = mysql.createPool({
host: "db-mysql-nyc1-99306-do-user-12431193-0.b.db.ondigitalocean.com",
user: "doadmin",
password: "AVNS_EPHqPilzmVjZfm8GH4G",
database: "defaultdb",
port: "25060",
waitForConnections: true,
connectionLimit: 10, // Number of connections in the pool
queueLimit: 0, // No limit on queued connection requests
connectTimeout: 20000 // 20 seconds
});
// Test the pool connection
pool.getConnection()
.then(conn => {
console.log("Connected to the MySQL POOL database.");
conn.release(); // Release the connection back to the pool
})
.catch(err => {
console.error("Database connection failed: " + err.stack);
});
export default pool;