Files
tiandihe/backend/database.py

20 lines
514 B
Python
Raw Permalink Normal View History

import os
import cx_Oracle
from dotenv import load_dotenv
load_dotenv()
ORACLE_DSN = os.getenv("ORACLE_DSN", "localhost:1521/ORCL")
ORACLE_USER = os.getenv("ORACLE_USER", "pltm")
ORACLE_PASSWORD = os.getenv("ORACLE_PASSWORD", "password")
def get_connection() -> cx_Oracle.Connection:
"""Return a new Oracle DB connection. Caller is responsible for closing."""
return cx_Oracle.connect(
user=ORACLE_USER,
password=ORACLE_PASSWORD,
dsn=ORACLE_DSN,
encoding="UTF-8",
)