Initial commit - Church Music Database

This commit is contained in:
2026-01-27 18:04:50 -06:00
commit d367261867
336 changed files with 103545 additions and 0 deletions

50
new-site/backend/db.js Normal file
View File

@@ -0,0 +1,50 @@
const { Pool } = require("pg");
require("dotenv").config();
// Parse PostgreSQL URI
const connectionString =
process.env.POSTGRESQL_URI ||
"postgresql://songlyric_user:MySecurePass123@192.168.10.130:5432/church_songlyric";
const pool = new Pool({
connectionString,
max: 20,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 10000,
});
// Test connection on startup
pool
.connect()
.then((client) => {
console.log("✅ Connected to PostgreSQL database");
client.release();
})
.catch((err) => {
console.error("❌ Failed to connect to PostgreSQL:", err.message);
});
// Query helper
const query = async (text, params) => {
const start = Date.now();
try {
const res = await pool.query(text, params);
const duration = Date.now() - start;
if (duration > 100) {
console.log("Slow query:", {
text: text.substring(0, 100),
duration,
rows: res.rowCount,
});
}
return res;
} catch (err) {
console.error("Query error:", err.message);
throw err;
}
};
module.exports = {
pool,
query,
};