dbhydra 2.2.3__tar.gz → 2.2.6__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.2.3 → dbhydra-2.2.6}/PKG-INFO +1 -1
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/src/abstract_table.py +11 -8
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/src/tables.py +15 -12
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra.egg-info/PKG-INFO +1 -1
- {dbhydra-2.2.3 → dbhydra-2.2.6}/setup.py +1 -1
- {dbhydra-2.2.3 → dbhydra-2.2.6}/LICENSE +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/README.md +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/__init__.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/dbhydra_core.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/src/__init__.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/src/abstract_db.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/src/bigquery_db.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/src/errors/__init__.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/src/errors/exceptions.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/src/migrator.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/src/mongo_db.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/src/mysql_db.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/src/postgres_db.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/src/sqlserver_db.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/src/xlsx_db.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/test_migrator.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/tests/__init__.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/tests/test_cases.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/tests/test_mongo.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra/tests/test_sql.py +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra.egg-info/SOURCES.txt +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra.egg-info/dependency_links.txt +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra.egg-info/requires.txt +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/dbhydra.egg-info/top_level.txt +0 -0
- {dbhydra-2.2.3 → dbhydra-2.2.6}/setup.cfg +0 -0
|
@@ -258,21 +258,23 @@ class AbstractTable(AbstractJoinable, abc.ABC):
|
|
|
258
258
|
return cls(db1, name, columns, types, id_column_name=id_column_name)
|
|
259
259
|
|
|
260
260
|
|
|
261
|
-
def drop(self):
|
|
261
|
+
def drop(self, debug_mode = False):
|
|
262
262
|
query = "DROP TABLE " + self.name
|
|
263
|
-
|
|
263
|
+
if debug_mode:
|
|
264
|
+
print(query)
|
|
264
265
|
self.execute(query)
|
|
265
266
|
|
|
266
|
-
def update(self, variable_assign, where=None):
|
|
267
|
+
def update(self, variable_assign, where=None, debug_mode = False):
|
|
267
268
|
if where is None:
|
|
268
269
|
query = "UPDATE " + self.name + " SET " + variable_assign
|
|
269
270
|
else:
|
|
270
271
|
query = "UPDATE " + self.name + " SET " + variable_assign + " WHERE " + where
|
|
271
|
-
|
|
272
|
+
if debug_mode:
|
|
273
|
+
print(query)
|
|
272
274
|
return self.execute(query)
|
|
273
275
|
|
|
274
276
|
def update_from_df(
|
|
275
|
-
self, update_df: pd.DataFrame, where_column: Optional[str] = None, where_value: Any = None) -> None:
|
|
277
|
+
self, update_df: pd.DataFrame, where_column: Optional[str] = None, where_value: Any = None, debug_mode = False) -> None:
|
|
276
278
|
"""Build UPDATE SQL query from a dataframe and execute it.
|
|
277
279
|
|
|
278
280
|
:param update_df: Dataframe with updated values - MUST only hold a single row
|
|
@@ -322,8 +324,8 @@ class AbstractTable(AbstractJoinable, abc.ABC):
|
|
|
322
324
|
sql_query += f" WHERE {where_column} = {where_value};"
|
|
323
325
|
else:
|
|
324
326
|
sql_query += ";"
|
|
325
|
-
|
|
326
|
-
|
|
327
|
+
if debug_mode:
|
|
328
|
+
print(sql_query)
|
|
327
329
|
self.execute(sql_query)
|
|
328
330
|
|
|
329
331
|
def _adjust_df(self, df: pd.DataFrame, debug_mode=False) -> pd.DataFrame:
|
|
@@ -398,7 +400,8 @@ class AbstractTable(AbstractJoinable, abc.ABC):
|
|
|
398
400
|
|
|
399
401
|
# TODO: handling nan values -> change to NULL
|
|
400
402
|
for column in list(df.columns):
|
|
401
|
-
|
|
403
|
+
|
|
404
|
+
df[column] = df[column].fillna("NULL") #New implementation, Old implementation was deprecated by pandas: #df.loc[pd.isna(df[column]), column] = "NULL"
|
|
402
405
|
|
|
403
406
|
# rows = df.values.tolist()
|
|
404
407
|
# for i, row in enumerate(rows):
|
|
@@ -141,7 +141,7 @@ class PostgresTable(AbstractTable):
|
|
|
141
141
|
return (cls(db1, name, columns, types))
|
|
142
142
|
|
|
143
143
|
# @save_migration
|
|
144
|
-
def create(self, foreign_keys=None):
|
|
144
|
+
def create(self, foreign_keys=None, debug_mode = False):
|
|
145
145
|
assert len(self.columns) == len(self.types)
|
|
146
146
|
assert self.columns[0] == self.id_column_name
|
|
147
147
|
assert self.types[0].lower() == "int" or self.types[0].lower() == "integer"
|
|
@@ -151,7 +151,8 @@ class PostgresTable(AbstractTable):
|
|
|
151
151
|
|
|
152
152
|
query = query[:-1]
|
|
153
153
|
query += ");"
|
|
154
|
-
|
|
154
|
+
if debug_mode:
|
|
155
|
+
print(query)
|
|
155
156
|
try:
|
|
156
157
|
self.db1.execute(query)
|
|
157
158
|
except Exception as e:
|
|
@@ -293,11 +294,12 @@ class BigQueryTable(AbstractSelectable):
|
|
|
293
294
|
return column_names, column_types
|
|
294
295
|
|
|
295
296
|
|
|
296
|
-
def select(self, query):
|
|
297
|
+
def select(self, query, debug_mode = False):
|
|
297
298
|
|
|
298
299
|
"""given SELECT query returns Python list"""
|
|
299
300
|
"""Columns give the number of selected columns"""
|
|
300
|
-
|
|
301
|
+
if debug_mode:
|
|
302
|
+
print(query)
|
|
301
303
|
# rows = self.db1.client.query(query).result()
|
|
302
304
|
rows = self.db1.execute(query)
|
|
303
305
|
return rows
|
|
@@ -495,7 +497,7 @@ class SqlServerTable(AbstractTable):
|
|
|
495
497
|
types = information_schema_table.select(query)
|
|
496
498
|
return (types)
|
|
497
499
|
|
|
498
|
-
def create(self):
|
|
500
|
+
def create(self, debug_mode = False):
|
|
499
501
|
assert len(self.columns) == len(self.types)
|
|
500
502
|
assert self.columns[0] == self.id_column_name
|
|
501
503
|
assert self.types[0].lower() == "int"
|
|
@@ -503,8 +505,8 @@ class SqlServerTable(AbstractTable):
|
|
|
503
505
|
for i in range(1, len(self.columns)):
|
|
504
506
|
query += self.columns[i] + " " + self.types[i] + ","
|
|
505
507
|
query += "PRIMARY KEY("+self.id_column_name+"))"
|
|
506
|
-
|
|
507
|
-
|
|
508
|
+
if debug_mode:
|
|
509
|
+
print(query)
|
|
508
510
|
try:
|
|
509
511
|
self.db1.execute(query)
|
|
510
512
|
except Exception as e:
|
|
@@ -729,13 +731,14 @@ class MysqlTable(AbstractTable):
|
|
|
729
731
|
|
|
730
732
|
return num_of_records[0][0]
|
|
731
733
|
|
|
732
|
-
def drop(self):
|
|
734
|
+
def drop(self, debug_mode = False):
|
|
733
735
|
query = "DROP TABLE `" + self.name + "`;"
|
|
734
|
-
|
|
736
|
+
if debug_mode:
|
|
737
|
+
print(query)
|
|
735
738
|
self.db1.execute(query)
|
|
736
739
|
|
|
737
740
|
# @save_migration #TODO: Uncomment
|
|
738
|
-
def create(self, foreign_keys=None):
|
|
741
|
+
def create(self, foreign_keys=None, debug_mode = False):
|
|
739
742
|
assert len(self.columns) == len(self.types)
|
|
740
743
|
assert self.columns[0] == self.id_column_name
|
|
741
744
|
assert self.types[0].lower() == "int"
|
|
@@ -745,8 +748,8 @@ class MysqlTable(AbstractTable):
|
|
|
745
748
|
[f"`{column}` {type_.upper()}" for column, type_ in column_type_pairs]
|
|
746
749
|
)
|
|
747
750
|
query = f"CREATE TABLE `{self.name}` ({self.id_column_name} INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, {fields})"
|
|
748
|
-
|
|
749
|
-
|
|
751
|
+
if debug_mode:
|
|
752
|
+
print(query)
|
|
750
753
|
try:
|
|
751
754
|
self.db1.execute(query)
|
|
752
755
|
except Exception as e:
|
|
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
|
|
File without changes
|