dbhydra 2.2.1__tar.gz → 2.2.5__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.1 → dbhydra-2.2.5}/PKG-INFO +1 -1
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/src/abstract_table.py +18 -14
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/src/tables.py +12 -10
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra.egg-info/PKG-INFO +1 -1
- {dbhydra-2.2.1 → dbhydra-2.2.5}/setup.py +1 -1
- {dbhydra-2.2.1 → dbhydra-2.2.5}/LICENSE +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/README.md +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/__init__.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/dbhydra_core.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/src/__init__.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/src/abstract_db.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/src/bigquery_db.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/src/errors/__init__.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/src/errors/exceptions.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/src/migrator.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/src/mongo_db.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/src/mysql_db.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/src/postgres_db.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/src/sqlserver_db.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/src/xlsx_db.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/test_migrator.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/tests/__init__.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/tests/test_cases.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/tests/test_mongo.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra/tests/test_sql.py +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra.egg-info/SOURCES.txt +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra.egg-info/dependency_links.txt +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra.egg-info/requires.txt +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/dbhydra.egg-info/top_level.txt +0 -0
- {dbhydra-2.2.1 → dbhydra-2.2.5}/setup.cfg +0 -0
|
@@ -102,7 +102,7 @@ class AbstractSelectable:
|
|
|
102
102
|
return (results)
|
|
103
103
|
|
|
104
104
|
|
|
105
|
-
def select(self, query, flattening_of_results=False):
|
|
105
|
+
def select(self, query, flattening_of_results=False, debug_mode = False):
|
|
106
106
|
"""given SELECT query returns Python list"""
|
|
107
107
|
"""Columns give the number of selected columns"""
|
|
108
108
|
|
|
@@ -113,7 +113,8 @@ class AbstractSelectable:
|
|
|
113
113
|
return(self) #to enable chaining
|
|
114
114
|
|
|
115
115
|
else:
|
|
116
|
-
|
|
116
|
+
if debug_mode:
|
|
117
|
+
print(query)
|
|
117
118
|
self.db1.cursor.execute(query)
|
|
118
119
|
|
|
119
120
|
columns_count=len(self._get_selected_columns(query))
|
|
@@ -131,18 +132,18 @@ class AbstractSelectable:
|
|
|
131
132
|
return(rows)
|
|
132
133
|
|
|
133
134
|
|
|
134
|
-
def select_all(self):
|
|
135
|
+
def select_all(self, debug_mode = False):
|
|
135
136
|
quote = self.db1.identifier_quote
|
|
136
137
|
all_cols_query = ""
|
|
137
138
|
for col in self.columns:
|
|
138
139
|
all_cols_query = all_cols_query + quote + col + quote + ","
|
|
139
140
|
if all_cols_query[-1] == ",":
|
|
140
141
|
all_cols_query = all_cols_query[:-1]
|
|
141
|
-
list1 = self.select(f"SELECT {all_cols_query} FROM {quote}{self.name}{quote};")
|
|
142
|
+
list1 = self.select(f"SELECT {all_cols_query} FROM {quote}{self.name}{quote};", debug_mode = debug_mode)
|
|
142
143
|
return (list1)
|
|
143
144
|
|
|
144
|
-
def select_to_df(self):
|
|
145
|
-
rows = self.select_all()
|
|
145
|
+
def select_to_df(self, debug_mode = False):
|
|
146
|
+
rows = self.select_all(debug_mode = debug_mode)
|
|
146
147
|
if self.query_building_enabled:
|
|
147
148
|
self.to_df()
|
|
148
149
|
df=None
|
|
@@ -257,21 +258,23 @@ class AbstractTable(AbstractJoinable, abc.ABC):
|
|
|
257
258
|
return cls(db1, name, columns, types, id_column_name=id_column_name)
|
|
258
259
|
|
|
259
260
|
|
|
260
|
-
def drop(self):
|
|
261
|
+
def drop(self, debug_mode = False):
|
|
261
262
|
query = "DROP TABLE " + self.name
|
|
262
|
-
|
|
263
|
+
if debug_mode:
|
|
264
|
+
print(query)
|
|
263
265
|
self.execute(query)
|
|
264
266
|
|
|
265
|
-
def update(self, variable_assign, where=None):
|
|
267
|
+
def update(self, variable_assign, where=None, debug_mode = False):
|
|
266
268
|
if where is None:
|
|
267
269
|
query = "UPDATE " + self.name + " SET " + variable_assign
|
|
268
270
|
else:
|
|
269
271
|
query = "UPDATE " + self.name + " SET " + variable_assign + " WHERE " + where
|
|
270
|
-
|
|
272
|
+
if debug_mode:
|
|
273
|
+
print(query)
|
|
271
274
|
return self.execute(query)
|
|
272
275
|
|
|
273
276
|
def update_from_df(
|
|
274
|
-
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:
|
|
275
278
|
"""Build UPDATE SQL query from a dataframe and execute it.
|
|
276
279
|
|
|
277
280
|
:param update_df: Dataframe with updated values - MUST only hold a single row
|
|
@@ -314,14 +317,15 @@ class AbstractTable(AbstractJoinable, abc.ABC):
|
|
|
314
317
|
raise AttributeError(f"Unknown column type '{column_type}'")
|
|
315
318
|
|
|
316
319
|
column_value_string = column_value_string.rstrip(", ")
|
|
317
|
-
|
|
320
|
+
quote = self.db1.identifier_quote
|
|
321
|
+
sql_query = f"UPDATE {quote}{self.name}{quote} SET {column_value_string}"
|
|
318
322
|
|
|
319
323
|
if where_column is not None and where_value is not None:
|
|
320
324
|
sql_query += f" WHERE {where_column} = {where_value};"
|
|
321
325
|
else:
|
|
322
326
|
sql_query += ";"
|
|
323
|
-
|
|
324
|
-
|
|
327
|
+
if debug_mode:
|
|
328
|
+
print(sql_query)
|
|
325
329
|
self.execute(sql_query)
|
|
326
330
|
|
|
327
331
|
def _adjust_df(self, df: pd.DataFrame, debug_mode=False) -> pd.DataFrame:
|
|
@@ -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:
|
|
@@ -495,7 +496,7 @@ class SqlServerTable(AbstractTable):
|
|
|
495
496
|
types = information_schema_table.select(query)
|
|
496
497
|
return (types)
|
|
497
498
|
|
|
498
|
-
def create(self):
|
|
499
|
+
def create(self, debug_mode = False):
|
|
499
500
|
assert len(self.columns) == len(self.types)
|
|
500
501
|
assert self.columns[0] == self.id_column_name
|
|
501
502
|
assert self.types[0].lower() == "int"
|
|
@@ -503,8 +504,8 @@ class SqlServerTable(AbstractTable):
|
|
|
503
504
|
for i in range(1, len(self.columns)):
|
|
504
505
|
query += self.columns[i] + " " + self.types[i] + ","
|
|
505
506
|
query += "PRIMARY KEY("+self.id_column_name+"))"
|
|
506
|
-
|
|
507
|
-
|
|
507
|
+
if debug_mode:
|
|
508
|
+
print(query)
|
|
508
509
|
try:
|
|
509
510
|
self.db1.execute(query)
|
|
510
511
|
except Exception as e:
|
|
@@ -729,13 +730,14 @@ class MysqlTable(AbstractTable):
|
|
|
729
730
|
|
|
730
731
|
return num_of_records[0][0]
|
|
731
732
|
|
|
732
|
-
def drop(self):
|
|
733
|
+
def drop(self, debug_mode = False):
|
|
733
734
|
query = "DROP TABLE `" + self.name + "`;"
|
|
734
|
-
|
|
735
|
+
if debug_mode:
|
|
736
|
+
print(query)
|
|
735
737
|
self.db1.execute(query)
|
|
736
738
|
|
|
737
739
|
# @save_migration #TODO: Uncomment
|
|
738
|
-
def create(self, foreign_keys=None):
|
|
740
|
+
def create(self, foreign_keys=None, debug_mode = False):
|
|
739
741
|
assert len(self.columns) == len(self.types)
|
|
740
742
|
assert self.columns[0] == self.id_column_name
|
|
741
743
|
assert self.types[0].lower() == "int"
|
|
@@ -745,8 +747,8 @@ class MysqlTable(AbstractTable):
|
|
|
745
747
|
[f"`{column}` {type_.upper()}" for column, type_ in column_type_pairs]
|
|
746
748
|
)
|
|
747
749
|
query = f"CREATE TABLE `{self.name}` ({self.id_column_name} INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, {fields})"
|
|
748
|
-
|
|
749
|
-
|
|
750
|
+
if debug_mode:
|
|
751
|
+
print(query)
|
|
750
752
|
try:
|
|
751
753
|
self.db1.execute(query)
|
|
752
754
|
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
|