You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
import psycopg2
|
|
import sys
|
|
import os
|
|
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
|
|
|
|
from src.config import DATABASE_HOSTNAME, DATABASE_PORT, COLLECTOR_HOSTNAME, COLLECTOR_PORT
|
|
|
|
def get_production_connection():
|
|
try:
|
|
# Konfigurasi koneksi database produksi
|
|
production_connection = psycopg2.connect(
|
|
dbname=COLLECTOR_NAME,
|
|
user=COLLECTOR_CREDENTIAL_USER,
|
|
password=COLLECTOR_CREDENTIAL_PASSWORD,
|
|
host=COLLECTOR_HOSTNAME,
|
|
port=COLLECTOR_PORT,
|
|
)
|
|
return production_connection
|
|
except Exception as e:
|
|
print("Error saat koneksi ke database produksi:", e)
|
|
return None
|
|
|
|
def get_connection():
|
|
try:
|
|
# Konfigurasi koneksi database
|
|
|
|
# connection = psycopg2.connect(
|
|
# host="localhost",
|
|
# port=5432,
|
|
# database="postgres",
|
|
# user="postgres",
|
|
# password="ariwa"
|
|
# )
|
|
connection = psycopg2.connect(
|
|
dbname=DATABASE_NAME,
|
|
user=DATABASE_CREDENTIAL_USER,
|
|
password=DATABASE_CREDENTIAL_PASSWORD,
|
|
host=DATABASE_HOSTNAME,
|
|
port=DATABASE_PORT,
|
|
)
|
|
connection_wo_db = psycopg2.connect(
|
|
dbname=COLLECTOR_NAME,
|
|
user=COLLECTOR_CREDENTIAL_USER,
|
|
password=COLLECTOR_CREDENTIAL_PASSWORD,
|
|
host=COLLECTOR_HOSTNAME,
|
|
port=COLLECTOR_PORT,
|
|
)
|
|
return connection, connection_wo_db
|
|
except Exception as e:
|
|
print("Error saat koneksi ke database:", e)
|
|
return None
|