-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: teste de conexão do python com postgres
- Loading branch information
1 parent
3c10ece
commit 46f155c
Showing
2 changed files
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
psycopg2-binary==2.9.3 | ||
sqlalchemy==2.0.21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |