bbdd-utils 0.3.10__py3-none-any.whl → 0.3.12__py3-none-any.whl

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/utils.py CHANGED
@@ -74,6 +74,7 @@ def Insert(conn, tabla, data):
74
74
  if isinstance(conn, sqlite3.Connection):
75
75
  print("Conexión exitosa a la base de datos SQL.")
76
76
  cursor = conn.cursor()
77
+
77
78
  # Crear la tabla dinámicamente si no existe
78
79
  columnas_definicion = ", ".join([f"{col} TEXT" for col in columnas])
79
80
  cursor.execute(f"""
@@ -84,12 +85,20 @@ def Insert(conn, tabla, data):
84
85
  """)
85
86
  print(f"Tabla '{tabla}' verificada o creada exitosamente.")
86
87
 
87
- # Inserta datos en la tabla
88
- placeholders = ", ".join(["?" for _ in columnas])
89
- cursor.execute(f"INSERT INTO {tabla} ({', '.join(columnas)}) VALUES ({placeholders})", valores)
88
+ # Si `data` es un solo diccionario, conviértelo en una lista
89
+ if isinstance(data, dict):
90
+ data = [data]
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()))
90
99
  conn.commit()
91
- print(f"Datos insertados correctamente en la tabla '{tabla}' de la base de datos SQL.")
92
-
100
+ print("Datos insertados correctamente en SQLite.")
101
+
93
102
  # Consulta los datos insertados
94
103
  cursor.execute("SELECT * FROM {tabla}")
95
104
  resultados = cursor.fetchall()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bbdd_utils
3
- Version: 0.3.10
3
+ Version: 0.3.12
4
4
  Summary: insertar datos en una base de datos SQL o NoSQL
5
5
  Author: Luis_J_Domingo
6
6
  Description-Content-Type: text/markdown
@@ -0,0 +1,7 @@
1
+ bbdd_utils/__init__.py,sha256=mjRX7GqWkOJq66KqghZ4MZE0Aai6R89LPeu1mjq4lD4,121
2
+ bbdd_utils/utils.py,sha256=fofJN6Cm1GlKnBpgMA3j4UxGgUAX9Zbo3zaMJu7jpY8,5557
3
+ bbdd_utils-0.3.12.dist-info/licenses/LICENSE,sha256=D4uqg6QX0fapLNcdUznOuGaRIUPnypOdeE2zIyYq7xY,217
4
+ bbdd_utils-0.3.12.dist-info/METADATA,sha256=pQmlHxiHRVOt9nrvp5TQlE5qBoYRsaC9Te7jB7lFjzA,694
5
+ bbdd_utils-0.3.12.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
6
+ bbdd_utils-0.3.12.dist-info/top_level.txt,sha256=bBGkVkxnOw7tZ2zRcyCM3lgVgYo1hFbcmwkGdKAj9Gk,11
7
+ bbdd_utils-0.3.12.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- bbdd_utils/__init__.py,sha256=mjRX7GqWkOJq66KqghZ4MZE0Aai6R89LPeu1mjq4lD4,121
2
- bbdd_utils/utils.py,sha256=eDco-IZrcw-vgzvAo6r9KMTrQ2YGC4IDRokR5A8yPjc,5244
3
- bbdd_utils-0.3.10.dist-info/licenses/LICENSE,sha256=D4uqg6QX0fapLNcdUznOuGaRIUPnypOdeE2zIyYq7xY,217
4
- bbdd_utils-0.3.10.dist-info/METADATA,sha256=P7NGLn7LmYrP-wouByVyVCb59qnrK8mDYeDoOWLYJBI,694
5
- bbdd_utils-0.3.10.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
6
- bbdd_utils-0.3.10.dist-info/top_level.txt,sha256=bBGkVkxnOw7tZ2zRcyCM3lgVgYo1hFbcmwkGdKAj9Gk,11
7
- bbdd_utils-0.3.10.dist-info/RECORD,,