Overview
DEMET Backend uses PostgreSQL as its relational database, managing hotel reservations, spaces, rates, partners, extras, and employees. The database is accessed through a connection pool for optimal performance.Database Connection
The application uses thepg (node-postgres) library with connection pooling.
Connection Configuration
Connection String Format
PostgreSQL user with appropriate permissions
User password (URL-encoded if contains special characters)
Database host (e.g.,
localhost, db.example.com)PostgreSQL port (default: 5432)
Database name
Connection Pool
Connection pooling improves performance by reusing database connections.Benefits
Performance
Reuses connections instead of creating new ones for each request
Scalability
Handles concurrent requests efficiently
Resource Management
Limits maximum connections to prevent overwhelming the database
Automatic Reconnection
Handles connection failures and reconnects automatically
Configuration Options
Database Schema
The DEMET Backend manages several core entities:Entity Relationships
Core Tables
EMPLOYEE
Stores employee information for authentication and authorization.Passwords are hashed using bcrypt before storage. Never store plain text passwords!
RESERVATION
Core table for managing hotel/space reservations.SPACE
Defines available spaces/rooms for reservation.RATE
Pricing rates for different customer types (partner/non-partner).PARTNER
Registered partners who receive discounted rates.EXTRA
Additional services/items that can be added to reservations.REQUEST
Reservation requests pending approval.Stored Procedures
The application uses PostgreSQL stored procedures for complex operations.Reservation Operations
Using Stored Procedures
Database Views
Views for reporting and analytics:REPORT View
estimated_report View
Database Functions
Price Calculation Function
Query Examples
Get All Active Reservations
Get Partner Reservations
Get Revenue by Space
Performance Optimization
Indexes
Connection Pool Best Practices
Database Migrations
For schema changes, consider using a migration tool:Backup and Restore
Backup Database
Restore Database
Troubleshooting
Connection timeout
Connection timeout
- Check PostgreSQL is running:
systemctl status postgresql - Verify firewall rules allow connections
- Increase
connectionTimeoutMillisin pool config - Check
max_connectionsin PostgreSQL config
Too many connections
Too many connections
- Reduce pool
maxsize - Check for connection leaks (unreleased clients)
- Increase PostgreSQL
max_connections - Use connection pooler like PgBouncer
Slow queries
Slow queries
- Add indexes on frequently queried columns
- Use
EXPLAIN ANALYZEto identify bottlenecks - Optimize complex joins
- Consider materialized views for reports
SSL connection error
SSL connection error
- For production, enable SSL in pool config
- For local development, disable SSL
Next Steps
Email Notifications
Set up automated email alerts
Reports
Generate Excel reports from database
API Reference
Explore database-backed endpoints
Configuration
Configure database connection strings