Skip to content

Commit

Permalink
Adicionando classe item e as 3 operações básicas do banco
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur-suares committed Nov 28, 2023
1 parent 6046431 commit 0989e27
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion game/Banco/FazMissao.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def inserirFazMissao(self, personagem: int, nomeMissao: str, status: bool):
def deletarFazMissao(self, personagem: int):
try:
conexao = self.db.conexao
cursor = conexao.cursor
cursor = conexao.cursor()

cursor.execute(f"DELETE FROM fazmissao WHERE personagem = '{personagem}';")
delecaoFazMissao = cursor.commit()
Expand Down
84 changes: 84 additions & 0 deletions game/Banco/Item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import psycopg2
from Database import Database

class Item:

def __init__(self, idItem: int, atcItem: int):
self.idItem = idItem
self.atcItem = atcItem
pass

def __init__(self):
self.db = Database()
pass

def inserirItem(self, idItem: int, atcItem: int):
try:
conexao = self.db.conexao
cursor = conexao.cursor()

cursor.execute("INSERT INTO item VALUES(%s, %s);", (idItem, atcItem))
insercaoFazMissao = conexao.commit()
return print("Item inserido com sucesso!\n")

except psycopg2.IntegrityError as e:
print(f"Encontramos problemas ao fazer a insercao. Erro: {e}\n")

finally:
cursor.close()

def deletarItem(self, idItem: int):
try:
conexao = self.db.conexao
cursor = conexao.cursor()

cursor.execute(f"DELETE FROM item WHERE iditem = '{idItem}';")
delecaoFazMissao = cursor.commit()
return print("Item deletado com sucesso!\n")

except psycopg2.IntegrityError as e:
print(f"Encontramos problemas ao fazer a delecao. Erro: {e}\n")

finally:
cursor.close()

def consultarItemId(self, idItem: int):
try:
conexao = self.db.conexao
cursor = conexao.cursor()
cursor.execute(f"SELECT * FROM item WHERE iditem = '{idItem}';")
consulta = cursor.fetchall()

if not consulta:
print("Não foi há itens cadastrados\n")
else:
for i in consulta:
print(i)
return i

except psycopg2.IntegrityError as e:
print(f"Encontramos problemas ao fazer a consulta. Erro: {e}\n")

finally:
cursor.close()

def consultarItem(self):
try:
conexao = self.db.conexao
cursor = conexao.cursor()
cursor.execute(f"SELECT * FROM item;")
consulta = cursor.fetchall()

if not consulta:
print("Não foi há itens cadastrados\n")
else:
for i in consulta:
print(i)
return i

except psycopg2.IntegrityError as e:
print(f"Encontramos problemas ao fazer a consulta. Erro: {e}\n")

finally:
cursor.close()

0 comments on commit 0989e27

Please sign in to comment.