package dev.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Small helper that hands out PostgreSQL connections.
 * Every DAO calls getConnection() when it needs to talk to the database.
 */
public class DatabaseConnection {

    private static final String URL = "jdbc:postgresql://localhost:5432/restaurant_db"; // DB Server

    private static final String USER = "postgres"; // Your Username

    private static final String PASSWORD = "password"; // Your Password

    private DatabaseConnection() {

    }

    public static Connection getConnection()
            throws SQLException {

        // DriverManager opens a fresh TCP connection to PostgreSQL using the
        // JDBC URL and credentials above. The postgresql driver on the
        // classpath registers itself automatically, so no Class.forName needed.
        return DriverManager.getConnection(URL, USER, PASSWORD);
    }

}
