Create database.py
Browse files- database.py +26 -0
database.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import mysql.connector
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
+
def get_connection():
|
| 5 |
+
return mysql.connector.connect(
|
| 6 |
+
user=st.secrets["DB_USER"],
|
| 7 |
+
password=st.secrets["DB_PASS"],
|
| 8 |
+
host=st.secrets["DB_HOST"],
|
| 9 |
+
port=st.secrets["DB_PORT"],
|
| 10 |
+
database=st.secrets["DB_NAME"],
|
| 11 |
+
ssl_ca="ca.pem",
|
| 12 |
+
use_pure=True
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
def registrar_log_operacao(executor, operacao, detalhes):
|
| 16 |
+
try:
|
| 17 |
+
conn = get_connection()
|
| 18 |
+
cursor = conn.cursor()
|
| 19 |
+
cursor.execute(
|
| 20 |
+
"INSERT INTO app_logs_operacoes (nome_executor, operacao, detalhes) VALUES (%s, %s, %s)",
|
| 21 |
+
(executor, operacao, detalhes)
|
| 22 |
+
)
|
| 23 |
+
conn.commit()
|
| 24 |
+
conn.close()
|
| 25 |
+
except Exception as e:
|
| 26 |
+
st.error(f"Erro ao registrar log: {e}")
|