-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_monthly_expense.js
More file actions
30 lines (25 loc) · 913 Bytes
/
add_monthly_expense.js
File metadata and controls
30 lines (25 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const { Pool } = require('pg');
// Create a new instance of the Pool class
const pool = new Pool({
user: 'your_username',
host: 'localhost',
database: 'your_database',
password: 'your_password',
port: 5432, // Default PostgreSQL port
});
// Function to insert a monthly expense
async function insertMonthlyExpense(memberId, expenseName, amount, category, recurringDay) {
try {
const query = `
INSERT INTO monthly_expenses (member_id, expense_name, amount, category, recurring_day)
VALUES ($1, $2, $3, $4, $5)
RETURNING *`;
const values = [memberId, expenseName, amount, category, recurringDay];
const result = await pool.query(query, values);
console.log('Monthly expense inserted:', result.rows[0]);
} catch (error) {
console.error('Error inserting monthly expense:', error);
}
}
// Usage example
insertMonthlyExpense(1, 'Rent', 1000.00, 'Housing', 1);