dbhydra 2.3.0__tar.gz → 2.3.1__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.
- {dbhydra-2.3.0 → dbhydra-2.3.1}/PKG-INFO +7 -1
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/src/abstract_table.py +11 -4
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/src/tables.py +6 -4
- dbhydra-2.3.1/dbhydra/tests/test_mysql_ddl.py +91 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra.egg-info/PKG-INFO +7 -1
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra.egg-info/SOURCES.txt +1 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/setup.py +1 -1
- {dbhydra-2.3.0 → dbhydra-2.3.1}/LICENSE +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/README.md +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/__init__.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/dbhydra_core.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/src/__init__.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/src/abstract_db.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/src/bigquery_db.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/src/errors/__init__.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/src/errors/exceptions.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/src/migrator.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/src/mongo_db.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/src/mysql_db.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/src/postgres_db.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/src/sqlserver_db.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/src/xlsx_db.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/test_migrator.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/tests/__init__.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/tests/test_cases.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/tests/test_mongo.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra/tests/test_sql.py +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra.egg-info/dependency_links.txt +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra.egg-info/requires.txt +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/dbhydra.egg-info/top_level.txt +0 -0
- {dbhydra-2.3.0 → dbhydra-2.3.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dbhydra
|
|
3
|
-
Version: 2.3.
|
|
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
|
|
@@ -11,6 +11,12 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Requires-Python: >=3.6
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
+
Requires-Dist: pyodbc
|
|
15
|
+
Requires-Dist: pandas
|
|
16
|
+
Requires-Dist: pymysql
|
|
17
|
+
Requires-Dist: pymongo
|
|
18
|
+
Requires-Dist: google-cloud-bigquery
|
|
19
|
+
Requires-Dist: pydantic
|
|
14
20
|
|
|
15
21
|
# dbhydra
|
|
16
22
|
Data science friendly ORM (Object Relational Mapping) library combining Python, Pandas, and various SQL dialects
|
|
@@ -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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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)
|
|
@@ -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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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.
|
|
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
|
|
@@ -11,6 +11,12 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Requires-Python: >=3.6
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
+
Requires-Dist: pyodbc
|
|
15
|
+
Requires-Dist: pandas
|
|
16
|
+
Requires-Dist: pymysql
|
|
17
|
+
Requires-Dist: pymongo
|
|
18
|
+
Requires-Dist: google-cloud-bigquery
|
|
19
|
+
Requires-Dist: pydantic
|
|
14
20
|
|
|
15
21
|
# dbhydra
|
|
16
22
|
Data science friendly ORM (Object Relational Mapping) library combining Python, Pandas, and various SQL dialects
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|