-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrud_ferramentas.py
40 lines (34 loc) · 1.23 KB
/
crud_ferramentas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from db import connect_db
def listar_ferramentas():
conn = connect_db()
cur = conn.cursor()
cur.execute("SELECT * FROM aluguel_ferramentas.ferramentas ORDER BY id")
ferramentas = cur.fetchall()
cur.close()
conn.close()
return ferramentas
def adicionar_ferramenta(nome, descricao, preco):
# Formatar o preco para usar ponto como separador decimal
preco = str(preco).replace(',', '.')
conn = connect_db()
cur = conn.cursor()
cur.execute("INSERT INTO aluguel_ferramentas.ferramentas (nome, descricao, preco) VALUES (%s, %s, %s)", (nome, descricao, preco))
conn.commit()
cur.close()
conn.close()
def editar_ferramenta(id, nome, descricao, preco):
# Formatar o preco para usar ponto como separador decimal
preco = str(preco).replace(',', '.')
conn = connect_db()
cur = conn.cursor()
cur.execute("UPDATE aluguel_ferramentas.ferramentas SET nome=%s, descricao=%s, preco=%s WHERE id=%s", (nome, descricao, preco, id))
conn.commit()
cur.close()
conn.close()
def excluir_ferramenta(id):
conn = connect_db()
cur = conn.cursor()
cur.execute("DELETE FROM aluguel_ferramentas.ferramentas WHERE id=%s", (id,))
conn.commit()
cur.close()
conn.close()