From 46f155c0865166ebadf3abfce70e573bebb9614a Mon Sep 17 00:00:00 2001 From: JeffersonSenaa Date: Wed, 18 Dec 2024 00:45:40 -0300 Subject: [PATCH] =?UTF-8?q?Add:=20teste=20de=20conex=C3=A3o=20do=20python?= =?UTF-8?q?=20com=20postgres?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 2 ++ velho-oeste/main.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 requirements.txt create mode 100644 velho-oeste/main.py diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9602387 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +psycopg2-binary==2.9.3 +sqlalchemy==2.0.21 diff --git a/velho-oeste/main.py b/velho-oeste/main.py new file mode 100644 index 0000000..95b0033 --- /dev/null +++ b/velho-oeste/main.py @@ -0,0 +1,14 @@ +from sqlalchemy import create_engine + +def test_connection(): + try: + # Formato de URL de conexão do SQLAlchemy + engine = create_engine('postgresql://velho_oeste_user:vopassword@velho-oeste-postgres:5432/velho_oeste_db') + connection = engine.connect() + print("Conexão bem-sucedida ao banco de dados!") + connection.close() + except Exception as e: + print(f"Erro na conexão: {e}") + +if __name__ == "__main__": + test_connection()