dbhydra 2.3.0__py3-none-any.whl → 2.3.1__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.
@@ -269,10 +269,17 @@ class AbstractTable(AbstractJoinable, abc.ABC):
269
269
 
270
270
  def update(self, variable_assign, where=None, debug_mode = False):
271
271
  quote = self.db1.identifier_quote
272
- if where is None:
273
- query = f"UPDATE {quote}{self.name}{quote} SET {quote}{variable_assign}{quote}"
274
- else:
275
- query = f"UPDATE {quote}{self.name}{quote} SET {quote}{variable_assign}{quote} WHERE {quote}{where}{quote}"
272
+
273
+ query = f"UPDATE {quote}{self.name}{quote} SET {variable_assign}"
274
+
275
+ if where:
276
+ query += f" WHERE {where}"
277
+
278
+ #Old broken implementation it gives `` for the SQL syntax query
279
+ # if where is None:
280
+ # query = f"UPDATE {quote}{self.name}{quote} SET {quote}{variable_assign}{quote}"
281
+ # else:
282
+ # query = f"UPDATE {quote}{self.name}{quote} SET {quote}{variable_assign}{quote} WHERE {quote}{where}{quote}"
276
283
 
277
284
  if debug_mode:
278
285
  print(query)
dbhydra/src/tables.py CHANGED
@@ -38,7 +38,6 @@ PYTHON_TO_MYSQL_DATA_MAPPING = {
38
38
 
39
39
  def save_migration(function, *args, **kw): # decorator
40
40
  def new_function(instance, *args, **kw):
41
- print("TOTO TU")
42
41
  print(instance)
43
42
  print(*args)
44
43
  command = function.__name__
@@ -63,9 +62,12 @@ def save_migration(function, *args, **kw): # decorator
63
62
  print(migration_dict)
64
63
  # TODO: add other methods
65
64
 
66
- migrator = instance.db1.migrator
67
- migrator.migration_list.append(migration_dict)
68
- # migrator.migration_list_to_json()
65
+ if hasattr(instance.db1, 'migrator'):
66
+ migrator = instance.db1.migrator
67
+ migrator.migration_list.append(migration_dict)
68
+ # migrator.migration_list_to_json()
69
+ else:
70
+ print(f"[save_migration] WARNING: db1 object of type {type(instance.db1)} has no 'migrator' attribute. Migration not saved.")
69
71
  function(instance, *args, **kw)
70
72
 
71
73
  return (new_function)
@@ -0,0 +1,91 @@
1
+ ##### DDL (data definition language) tests for MySQL #####
2
+
3
+ import os
4
+ import pytest
5
+ import random
6
+ import string
7
+ import dbhydra.dbhydra_core as dh
8
+
9
+ def random_table_name(prefix="test_table_"):
10
+ return prefix + ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))
11
+
12
+ # Rename mysqldb fixture and all references to db1
13
+ @pytest.fixture(scope="module")
14
+ def db1():
15
+ # Get the directory of this test file, then go up one level to the project root
16
+ root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
17
+ config_path = os.path.join(root_dir, "config-mysql.ini")
18
+ return dh.MysqlDb(config_file=config_path)
19
+
20
+ @pytest.fixture(scope="function")
21
+ def temp_mysql_table(db1):
22
+ table_name = random_table_name()
23
+ columns = ["id", "name"]
24
+ types = ["int", "varchar(255)"]
25
+ table = dh.MysqlTable(db1, table_name, columns, types)
26
+ with db1.connect_to_db():
27
+ table.create()
28
+ table_dict = db1.generate_table_dict()
29
+ assert table_name in table_dict, f"Temp table {table_name} was not created!"
30
+ yield table
31
+ # Cleanup
32
+ try:
33
+ with db1.connect_to_db():
34
+ table.drop()
35
+ table_dict = db1.generate_table_dict()
36
+ assert table_name not in table_dict, f"Temp table {table_name} was not dropped!"
37
+ except Exception as e:
38
+ print(f"[CLEANUP] Could not drop table {table_name}: {e}")
39
+ raise
40
+
41
+ def test_mysql_create_and_drop_table(db1):
42
+ table_name = random_table_name()
43
+ columns = ["id", "name"]
44
+ types = ["int", "varchar(255)"]
45
+ table = dh.MysqlTable(db1, table_name, columns, types)
46
+ with db1.connect_to_db():
47
+ table.create()
48
+ table_dict = db1.generate_table_dict()
49
+ assert table_name in table_dict, f"Table {table_name} was not created!"
50
+ table.drop()
51
+ table_dict = db1.generate_table_dict()
52
+ assert table_name not in table_dict, f"Table {table_name} was not dropped!"
53
+
54
+ def test_mysql_add_column(temp_mysql_table, db1):
55
+ table = temp_mysql_table
56
+ column = "age"
57
+ type = "int"
58
+ with db1.connect_to_db():
59
+ table.add_column(column, type)
60
+ df = table.select_to_df()
61
+ columns = df.columns.tolist()
62
+ assert column in columns, f"Column '{column}' was not added! Columns: {columns}"
63
+
64
+ def test_mysql_drop_column(temp_mysql_table, db1):
65
+ table = temp_mysql_table
66
+ column = "age"
67
+ type = "int"
68
+ with db1.connect_to_db():
69
+ table.add_column(column, type)
70
+ df = table.select_to_df()
71
+ columns = df.columns.tolist()
72
+ assert column in columns, f"Column '{column}' was not added! Columns: {columns}"
73
+ table.drop_column(column)
74
+ df = table.select_to_df()
75
+ columns = df.columns.tolist()
76
+ assert column not in columns, f"Column '{column}' was not dropped! Columns: {columns}"
77
+
78
+ def test_mysql_modify_column(temp_mysql_table, db1):
79
+ table = temp_mysql_table
80
+ column = "age"
81
+ type = "int"
82
+ with db1.connect_to_db():
83
+ table.add_column(column, type)
84
+ df = table.select_to_df()
85
+ columns = df.columns.tolist()
86
+ assert column in columns, f"Column '{column}' was not added! Columns: {columns}"
87
+ # Modify column type
88
+ type2 = "varchar(100)"
89
+ table.modify_column(column, type2)
90
+ types = table.get_all_types()
91
+ assert any("varchar" in t for t in types), f"Column '{column}' was not modified to varchar! Types: {types}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dbhydra
3
- Version: 2.3.0
3
+ Version: 2.3.1
4
4
  Summary: Data science friendly ORM combining Python
5
5
  Home-page: https://github.com/DovaX/dbhydra
6
6
  Author: DovaX
@@ -3,23 +3,24 @@ dbhydra/dbhydra_core.py,sha256=jn0VC3LkawR2P0Yd_oZNEXqP9o2BPEtOBWGzgFwfJyA,2537
3
3
  dbhydra/test_migrator.py,sha256=e3Nnb2mCd3CfjhjSexNg1tXVJMjkl5cCoYcuhbfZ4pM,803
4
4
  dbhydra/src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  dbhydra/src/abstract_db.py,sha256=7Rv2XgdaKiQ5yBnU0EDh5uT8XbB3JI5Pis_in6iHn2c,7172
6
- dbhydra/src/abstract_table.py,sha256=FITmTqwLT6zB2WVVb3wSb8GAPZeLQfGR2u5vKTB8Ja4,19102
6
+ dbhydra/src/abstract_table.py,sha256=5sTNPpUD31l4UbZ0at5CMg-AbLlOYodpq_sHmT1Lrb8,19331
7
7
  dbhydra/src/bigquery_db.py,sha256=77XsgvYbANlvYaJnuVve-kz-PNBx_CHoYCL-eYnA8e4,1834
8
8
  dbhydra/src/migrator.py,sha256=QzaODEFfraD9_6HN_Osaidaj-nLYQryCYYWwJtUu3n8,18931
9
9
  dbhydra/src/mongo_db.py,sha256=mP48zRjI7mXKpm45R8prroZI-Eo7JKf0KJqGX-oTy3w,1922
10
10
  dbhydra/src/mysql_db.py,sha256=lNWaS3YHtQE1Xii-ErWUDhxeo3b6HWgXxQAMJfgiGEE,3583
11
11
  dbhydra/src/postgres_db.py,sha256=L7MaBq_6ArwDSP_5LaEqK58oLxZ1X7FgIokcDOSB7wk,1805
12
12
  dbhydra/src/sqlserver_db.py,sha256=9Xi3NAliqM79MTV8fpNQb0nWMH8Bqjl1leJSEqgyT94,3611
13
- dbhydra/src/tables.py,sha256=oRbSTIHjeSc5ZCHmn74ZqdOvtBZDy6t_fp2KO-Z_Y-8,47612
13
+ dbhydra/src/tables.py,sha256=Xt0c8o93ZthxTF6YF9TGS3Ud719qXSD3iF7-wGbckW4,47799
14
14
  dbhydra/src/xlsx_db.py,sha256=glFF-0dQK0GGinAqc2zvf9JQ9iAH9YkDAYd4Jb3oimQ,3616
15
15
  dbhydra/src/errors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  dbhydra/src/errors/exceptions.py,sha256=LVpfbTd3NHfQIM-D5TFAU6hOZwGQ3b5DwFD4B6vtf2U,149
17
17
  dbhydra/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  dbhydra/tests/test_cases.py,sha256=eAFGaHaIaab3md3HHm2_ryb_HHfObtcXDAEzLh4qWx8,508
19
19
  dbhydra/tests/test_mongo.py,sha256=M8TD72M0iQAk7ZcLTWwLmcmmF_zwALnYEGTWjhQlq0s,1979
20
+ dbhydra/tests/test_mysql_ddl.py,sha256=-gncZE_HjTOAI1yxOn8u5TZkoqoRdShLMF469Trbb9U,3531
20
21
  dbhydra/tests/test_sql.py,sha256=aPFXyA0jh8o9VG3B5f9fNz7qDbuVPZ9TcE2twn5dAeQ,3126
21
- dbhydra-2.3.0.dist-info/LICENSE,sha256=k49Yga8CP889JJaHlOpGFzr_be2nqMoep2chYeIDctk,1091
22
- dbhydra-2.3.0.dist-info/METADATA,sha256=zmqV5NBQcLq9SJY7QuUxUZomIJa_WuSeXku1HYs8JXc,2298
23
- dbhydra-2.3.0.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
24
- dbhydra-2.3.0.dist-info/top_level.txt,sha256=oO4Gf1T8_txIsIlp11GI0k7PtBIMb9GRwb5ObF4MLVg,8
25
- dbhydra-2.3.0.dist-info/RECORD,,
22
+ dbhydra-2.3.1.dist-info/LICENSE,sha256=k49Yga8CP889JJaHlOpGFzr_be2nqMoep2chYeIDctk,1091
23
+ dbhydra-2.3.1.dist-info/METADATA,sha256=Mwdf3U9g9K4GXTATZYRdO9qu1TZIYBREDdBp39YgSgk,2298
24
+ dbhydra-2.3.1.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
25
+ dbhydra-2.3.1.dist-info/top_level.txt,sha256=oO4Gf1T8_txIsIlp11GI0k7PtBIMb9GRwb5ObF4MLVg,8
26
+ dbhydra-2.3.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.38.4)
2
+ Generator: setuptools (75.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5