-
Notifications
You must be signed in to change notification settings - Fork 0
/
crud_reservas.py
61 lines (54 loc) · 1.93 KB
/
crud_reservas.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from db import connect_db
def listar_reservas():
conn = connect_db()
cur = conn.cursor()
cur.execute("SELECT * FROM aluguel_ferramentas.reservas ORDER BY id")
reservas = cur.fetchall()
cur.close()
conn.close()
return reservas
def adicionar_reserva(ferramenta_id, usuario_id, data_inicio, data_fim, status):
conn = connect_db()
cur = conn.cursor()
cur.execute("INSERT INTO aluguel_ferramentas.reservas (ferramenta_id, usuario_id, data_inicio, data_fim, status) VALUES (%s, %s, %s, %s, %s)", (ferramenta_id, usuario_id, data_inicio, data_fim, status))
conn.commit()
cur.close()
conn.close()
def editar_reserva(id, ferramenta_id, usuario_id, data_inicio, data_fim, status):
conn = connect_db()
cur = conn.cursor()
cur.execute("UPDATE aluguel_ferramentas.reservas SET ferramenta_id=%s, usuario_id=%s, data_inicio=%s, data_fim=%s, status=%s WHERE id=%s", (ferramenta_id, usuario_id, data_inicio, data_fim, status, id))
conn.commit()
cur.close()
conn.close()
def excluir_reserva(id):
conn = connect_db()
cur = conn.cursor()
cur.execute("DELETE FROM aluguel_ferramentas.reservas WHERE id=%s", (id,))
conn.commit()
cur.close()
conn.close()
def buscar_nome_ferramenta_por_id(id):
conn = connect_db()
cur = conn.cursor()
cur.execute("SELECT nome FROM aluguel_ferramentas.ferramentas WHERE id=%s", (id,))
nome = cur.fetchone()[0]
cur.close()
conn.close()
return nome
def buscar_nome_usuario_por_id(id):
conn = connect_db()
cur = conn.cursor()
cur.execute("SELECT nome FROM aluguel_ferramentas.usuarios WHERE id=%s", (id,))
nome = cur.fetchone()[0]
cur.close()
conn.close()
return nome
def buscar_reserva_por_id(id):
conn = connect_db()
cur = conn.cursor()
cur.execute("SELECT * FROM aluguel_ferramentas.reservas WHERE id=%s", (id,))
reserva = cur.fetchone()
cur.close()
conn.close()
return reserva