Skip to content

Commit 3c9e5bf

Browse files
CRUD CONSOLE
1 parent 026fb87 commit 3c9e5bf

File tree

5 files changed

+108
-1
lines changed

5 files changed

+108
-1
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"python.pythonPath": "C:\\Users\\brian\\AppData\\Local\\Programs\\Python\\Python39\\python.exe"
2+
"python.pythonPath": "/bin/python3"
33
}
632 Bytes
Binary file not shown.

Crud Console/conexion.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sqlite3
2+
#Import database
3+
database = "database.db"
4+
class DB:
5+
def ejecutar_consulta(self,consulta,parametros = ()):
6+
with sqlite3.connect(database) as conn:
7+
self.cursor = conn.cursor()
8+
result = self.cursor.execute(consulta,parametros)
9+
conn.commit()
10+
return result
11+

Crud Console/database.db

12 KB
Binary file not shown.

Crud Console/main.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from os import system
2+
import time
3+
import conexion as conn
4+
db = conn.DB()
5+
system("clear")
6+
7+
def create():
8+
name = str(input("INGRESA SU NOMBRE: "))
9+
email = str(input("INGRESA SU EMAIL: "))
10+
if(len(name) > 0 and len(email) > 0):
11+
sql = "INSERT INTO sistema(name,email) VALUES(?,?)"
12+
parametros = (name,email)
13+
db.ejecutar_consulta(sql,parametros)
14+
print("Insertados")
15+
16+
def read():
17+
sql = "SELECT * FROM sistema"
18+
result = db.ejecutar_consulta(sql)
19+
for data in result:
20+
print("""
21+
ID : {}
22+
NOMBRE : {}
23+
EMAIL : {}
24+
""".format(data[0],data[1],data[2]))
25+
26+
def update():
27+
id = int(input("INGRESA EL ID: "))
28+
if(id != 0):
29+
name = str(input("INGRESA SU NOMBRE: "))
30+
email = str(input("INGRESA SU EMAIL: "))
31+
if(len(name) > 0 and len(email) > 0):
32+
sql = "UPDATE sistema SET name=?,email=? WHERE id=?"
33+
parametros = (name,email,id)
34+
db.ejecutar_consulta(sql,parametros)
35+
print("Actualizado!")
36+
else:
37+
print("Se require un ID")
38+
39+
def delete():
40+
id = int(input("INGRESA EL ID: "))
41+
if(id != 0):
42+
sql = "DELETE FROM sistema WHERE id=?"
43+
parametros = (id,)
44+
db.ejecutar_consulta(sql,parametros)
45+
print("Eliminado!")
46+
else:
47+
print("Se require un ID")
48+
49+
def search():
50+
nombre = str(input("Buscar por nombre: "))
51+
if(len(nombre) > 0):
52+
sql = "SELECT * FROM sistema WHERE name LIKE ?"
53+
parametros = ('%{}%'.format(nombre),)
54+
result = db.ejecutar_consulta(sql,parametros)
55+
for data in result:
56+
print("""
57+
+ID : {}
58+
+NOMBRE : {}
59+
+EMAIL : {}""".format(data[0],data[1],data[2]))
60+
while True:
61+
print("=========================================")
62+
print("\tCRUD CON SQLite3")
63+
print("=========================================")
64+
print("\t[1] Insertar registro")
65+
print("\t[2] Listar registros")
66+
print("\t[3] Actualizar registros")
67+
print("\t[4] Eliminar registros")
68+
print("\t[5] Buscar registros")
69+
print("\t[6] Salir")
70+
print("=========================================")
71+
72+
try:
73+
opcion = int(input("Selecciona una opcion: "))
74+
if(opcion == 1):
75+
create()
76+
time.sleep(1)
77+
system("clear")
78+
elif (opcion == 2):
79+
read()
80+
time.sleep(1)
81+
elif (opcion == 3):
82+
update()
83+
time.sleep(1)
84+
system("clear")
85+
elif (opcion == 4):
86+
delete()
87+
time.sleep(1)
88+
system("clear")
89+
elif (opcion == 5):
90+
search()
91+
92+
elif (opcion == 6):
93+
break
94+
except:
95+
print("Por favor, selecciona las opciones correctas")
96+
system("clear")

0 commit comments

Comments
 (0)