bbdd-utils 0.3.12__tar.gz → 0.3.14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bbdd_utils-0.3.12 → bbdd_utils-0.3.14}/PKG-INFO +1 -1
- {bbdd_utils-0.3.12 → bbdd_utils-0.3.14}/bbdd_utils/utils.py +9 -16
- {bbdd_utils-0.3.12 → bbdd_utils-0.3.14}/bbdd_utils.egg-info/PKG-INFO +1 -1
- {bbdd_utils-0.3.12 → bbdd_utils-0.3.14}/setup.py +1 -1
- {bbdd_utils-0.3.12 → bbdd_utils-0.3.14}/LICENSE +0 -0
- {bbdd_utils-0.3.12 → bbdd_utils-0.3.14}/README.md +0 -0
- {bbdd_utils-0.3.12 → bbdd_utils-0.3.14}/bbdd_utils/__init__.py +0 -0
- {bbdd_utils-0.3.12 → bbdd_utils-0.3.14}/bbdd_utils.egg-info/SOURCES.txt +0 -0
- {bbdd_utils-0.3.12 → bbdd_utils-0.3.14}/bbdd_utils.egg-info/dependency_links.txt +0 -0
- {bbdd_utils-0.3.12 → bbdd_utils-0.3.14}/bbdd_utils.egg-info/top_level.txt +0 -0
- {bbdd_utils-0.3.12 → bbdd_utils-0.3.14}/pyproject.toml +0 -0
- {bbdd_utils-0.3.12 → bbdd_utils-0.3.14}/setup.cfg +0 -0
@@ -18,7 +18,9 @@ def Conector_bbdd(tipo='sqlite', nombre='mi_base_de_datos', host='localhost', pu
|
|
18
18
|
import os
|
19
19
|
nombre_db = f"{nombre}.db"
|
20
20
|
conn = sqlite3.connect(nombre_db)
|
21
|
+
print(f"Base de datos SQLite '{nombre_db}' creada exitosamente.")
|
21
22
|
return conn
|
23
|
+
|
22
24
|
|
23
25
|
elif tipo == 'mysql':
|
24
26
|
import mysql.connector
|
@@ -30,7 +32,7 @@ def Conector_bbdd(tipo='sqlite', nombre='mi_base_de_datos', host='localhost', pu
|
|
30
32
|
# Crear la base de datos
|
31
33
|
cursor = conn.cursor()
|
32
34
|
cursor.execute(f"CREATE DATABASE IF NOT EXISTS {nombre}")
|
33
|
-
print(f"Base de datos '{nombre}' creada exitosamente.")
|
35
|
+
print(f"Base de datos Mysql '{nombre}' creada exitosamente.")
|
34
36
|
return conn
|
35
37
|
|
36
38
|
elif tipo == 'mongodb':
|
@@ -41,7 +43,7 @@ def Conector_bbdd(tipo='sqlite', nombre='mi_base_de_datos', host='localhost', pu
|
|
41
43
|
port=puerto,
|
42
44
|
username=usuario,
|
43
45
|
password=password)
|
44
|
-
print("
|
46
|
+
print(f"Conexión exitosa a MongoDB en {host}:{puerto}.")
|
45
47
|
return cliente[nombre]
|
46
48
|
|
47
49
|
else:
|
@@ -74,7 +76,6 @@ def Insert(conn, tabla, data):
|
|
74
76
|
if isinstance(conn, sqlite3.Connection):
|
75
77
|
print("Conexión exitosa a la base de datos SQL.")
|
76
78
|
cursor = conn.cursor()
|
77
|
-
|
78
79
|
# Crear la tabla dinámicamente si no existe
|
79
80
|
columnas_definicion = ", ".join([f"{col} TEXT" for col in columnas])
|
80
81
|
cursor.execute(f"""
|
@@ -85,20 +86,12 @@ def Insert(conn, tabla, data):
|
|
85
86
|
""")
|
86
87
|
print(f"Tabla '{tabla}' verificada o creada exitosamente.")
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
if isinstance(data, tuple):
|
92
|
-
data = list(data)
|
93
|
-
# Inserta cada elemento de la lista en la tabla
|
94
|
-
for registro in data:
|
95
|
-
columnas = ", ".join(registro.keys())
|
96
|
-
valores = ", ".join(["?"] * len(registro))
|
97
|
-
query = f"INSERT INTO {tabla} ({columnas}) VALUES ({valores})"
|
98
|
-
cursor.execute(query, tuple(registro.values()))
|
89
|
+
# Inserta datos en la tabla
|
90
|
+
placeholders = ", ".join(["?" for _ in columnas])
|
91
|
+
cursor.execute(f"INSERT INTO {tabla} ({', '.join(columnas)}) VALUES ({placeholders})", valores)
|
99
92
|
conn.commit()
|
100
|
-
print("Datos insertados correctamente en
|
101
|
-
|
93
|
+
print(f"Datos insertados correctamente en la tabla '{tabla}' de la base de datos SQL.")
|
94
|
+
|
102
95
|
# Consulta los datos insertados
|
103
96
|
cursor.execute("SELECT * FROM {tabla}")
|
104
97
|
resultados = cursor.fetchall()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|