-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrud_util.py
More file actions
39 lines (33 loc) · 1.33 KB
/
crud_util.py
File metadata and controls
39 lines (33 loc) · 1.33 KB
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
from orator import DatabaseManager
from conexao import Conexao
class CrudUtil():
con = None
def __init__(self, link = 'padrao'):
self.con = Conexao(link)
def insert(self, tabela, camposValores):
try:
self.con.qb().begin_transaction()
id = self.con.qb().table(tabela).insert_get_id(camposValores)
self.con.qb().commit()
return id
except Exception as e:
self.con.qb().rollback()
raise Exception("Database transaction failed. Details: "+ str(e))
def update(self, tabela, where, camposValores):
try:
self.con.qb().begin_transaction()
id = self.con.qb().table(tabela).where(where).update(camposValores)
self.con.qb().commit()
return id
except Exception as e:
self.con.qb().rollback()
raise Exception("Database transaction failed. Details: " + str(e))
def delete(self, tabela, where):
try:
self.con.qb().begin_transaction()
id = self.con.qb().table(tabela).where(where).delete()
self.con.qb().commit()
return id
except Exception as e:
self.con.qb().rollback()
raise Exception("Database transaction failed. Details: " + str(e))