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.5 KiB
Python

import psycopg2
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from config import DATABASE_HOSTNAME, DATABASE_PORT, COLLECTOR_HOSTNAME, COLLECTOR_PORT
def get_production_connection():
try:
# Konfigurasi koneksi database produksi
production_connection = psycopg2.connect(
dbname="digital_twin",
user="digital_twin",
password="Pr0jec7@D!g!tTwiN",
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="digital_twin",
user="postgres",
password="postgres",
host={DATABASE_HOSTNAME},
port={DATABASE_PORT},
)
connection_wo_db = psycopg2.connect(
dbname="digital_twin",
user="postgres",
password="postgres",
host={COLLECTOR_HOSTNAME},
port={COLLECTOR_PORT},
)
return connection, connection_wo_db
except Exception as e:
print("Error saat koneksi ke database:", e)
return None