dbhydra 2.0.11__py3-none-any.whl → 2.0.13__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.
- dbhydra/src/abstract_table.py +6 -2
- dbhydra/src/mysql_db.py +2 -2
- dbhydra/src/tables.py +33 -0
- dbhydra/src/xlsx_db.py +16 -0
- {dbhydra-2.0.11.dist-info → dbhydra-2.0.13.dist-info}/METADATA +1 -1
- {dbhydra-2.0.11.dist-info → dbhydra-2.0.13.dist-info}/RECORD +9 -9
- {dbhydra-2.0.11.dist-info → dbhydra-2.0.13.dist-info}/LICENSE +0 -0
- {dbhydra-2.0.11.dist-info → dbhydra-2.0.13.dist-info}/WHEEL +0 -0
- {dbhydra-2.0.11.dist-info → dbhydra-2.0.13.dist-info}/top_level.txt +0 -0
dbhydra/src/abstract_table.py
CHANGED
|
@@ -238,8 +238,12 @@ class AbstractTable(AbstractJoinable, abc.ABC):
|
|
|
238
238
|
super().__init__(db1, name, columns)
|
|
239
239
|
self.types: list[str] = types #[] if types is None else types - is wrong, if types not initialized it should be None, not empty list
|
|
240
240
|
self.id_column_name: str = id_column_name
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
if self.columns is not None and self.types is not None:
|
|
242
|
+
assert len(self.columns) == len(self.types)
|
|
243
|
+
self.column_type_dict={self.columns[i]:self.types[i] for i,x in enumerate(self.columns)}
|
|
244
|
+
else:
|
|
245
|
+
self.column_type_dict={}
|
|
246
|
+
|
|
243
247
|
|
|
244
248
|
# Temporary disabled, please make sure this is implemented where needed, don't introduce breaking changes please
|
|
245
249
|
# @abc.abstractmethod
|
dbhydra/src/mysql_db.py
CHANGED
|
@@ -57,11 +57,11 @@ class MysqlDb(AbstractDb):
|
|
|
57
57
|
tables = [x[0] for x in rows]
|
|
58
58
|
return (tables)
|
|
59
59
|
|
|
60
|
-
def generate_table_dict(self):
|
|
60
|
+
def generate_table_dict(self, id_column_name = "id"):
|
|
61
61
|
tables = self.get_all_tables()
|
|
62
62
|
table_dict = dict()
|
|
63
63
|
for i, table in enumerate(tables):
|
|
64
|
-
table_dict[table] = MysqlTable.init_all_columns(self, table)
|
|
64
|
+
table_dict[table] = MysqlTable.init_all_columns(self, table, id_column_name)
|
|
65
65
|
return (table_dict)
|
|
66
66
|
|
|
67
67
|
|
dbhydra/src/tables.py
CHANGED
|
@@ -890,6 +890,39 @@ class XlsxTable(AbstractTable):
|
|
|
890
890
|
else:
|
|
891
891
|
df.to_excel(self.table_directory_path, index=False)
|
|
892
892
|
|
|
893
|
+
def get_all_columns(self):
|
|
894
|
+
df=self.select_to_df()
|
|
895
|
+
columns=df.columns.tolist()
|
|
896
|
+
return(columns)
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
def get_all_types(self):
|
|
900
|
+
df=self.select_to_df()
|
|
901
|
+
dtypes=df.dtypes.tolist()
|
|
902
|
+
types = [str(x) for x in dtypes]
|
|
903
|
+
clean_types=[x.replace("object","str") for x in types] #Todo support more types
|
|
904
|
+
|
|
905
|
+
return(clean_types)
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
@classmethod
|
|
910
|
+
def init_all_columns(cls, db1, name, id_column_name="id"):
|
|
911
|
+
temporary_table = cls(db1, name, id_column_name)
|
|
912
|
+
columns = temporary_table.get_all_columns()
|
|
913
|
+
types = temporary_table.get_all_types()
|
|
914
|
+
|
|
915
|
+
if temporary_table.id_column_name in columns:
|
|
916
|
+
id_col_index = columns.index(temporary_table.id_column_name)
|
|
917
|
+
columns.pop(id_col_index)
|
|
918
|
+
columns.insert(0, temporary_table.id_column_name)
|
|
919
|
+
types.pop(id_col_index)
|
|
920
|
+
types.insert(0, "int")
|
|
921
|
+
|
|
922
|
+
return (cls(db1, name, columns, types, id_column_name=id_column_name))
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
893
926
|
def create(self):
|
|
894
927
|
if not self.table_directory_path.exists():
|
|
895
928
|
df = pd.DataFrame(columns=self.columns)
|
dbhydra/src/xlsx_db.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from dbhydra.src.abstract_db import AbstractDb
|
|
2
2
|
from dbhydra.src.tables import XlsxTable
|
|
3
3
|
|
|
4
|
+
import contextlib
|
|
4
5
|
import threading
|
|
5
6
|
import pathlib
|
|
6
7
|
import os
|
|
@@ -84,7 +85,22 @@ class XlsxDb(AbstractDb):
|
|
|
84
85
|
except FileExistsError:
|
|
85
86
|
print("Database directory already exists")
|
|
86
87
|
|
|
88
|
+
@contextlib.contextmanager
|
|
89
|
+
def transaction(self):
|
|
90
|
+
yield None
|
|
87
91
|
|
|
92
|
+
def get_all_tables(self):
|
|
93
|
+
root,dirs,files=next(os.walk(self.db_directory_path))
|
|
94
|
+
suffix=".csv" if self.is_csv else ".xlsx"
|
|
95
|
+
tables = [x.lower().replace(suffix,"") for x in files]
|
|
96
|
+
return (tables)
|
|
97
|
+
|
|
98
|
+
def generate_table_dict(self, id_column_name="id"):
|
|
99
|
+
tables = self.get_all_tables()
|
|
100
|
+
table_dict = dict()
|
|
101
|
+
for i, table in enumerate(tables):
|
|
102
|
+
table_dict[table] = XlsxTable.init_all_columns(self, table, id_column_name)
|
|
103
|
+
return (table_dict)
|
|
88
104
|
|
|
89
105
|
|
|
90
106
|
class XlsxDB(XlsxDb):
|
|
@@ -11,23 +11,23 @@ dbhydra/mongo.py,sha256=GeNsv8rkt5DmjN7eEjvgJ5F9XUCwf8zir9DqbAuJswc,1836
|
|
|
11
11
|
dbhydra/test.py,sha256=SQDd8D_gpAE_14QFw5WCWJCsFq4iEnsvxoGD8vcB9G8,448
|
|
12
12
|
dbhydra/src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
dbhydra/src/abstract_db.py,sha256=tY4sNuRQw2qXMXxha9eo9tAmP2z_hcirf04tfDBpwxs,5607
|
|
14
|
-
dbhydra/src/abstract_table.py,sha256=
|
|
14
|
+
dbhydra/src/abstract_table.py,sha256=00f3Hb6LUbexvqZFPDaDwfS37Vll-ONwJfwCV-IVuto,16363
|
|
15
15
|
dbhydra/src/bigquery_db.py,sha256=77XsgvYbANlvYaJnuVve-kz-PNBx_CHoYCL-eYnA8e4,1834
|
|
16
16
|
dbhydra/src/migrator.py,sha256=l2MBmiAsv2hv97YmA5IvfbPUK2aAPt46jFulLXBUFHc,4412
|
|
17
17
|
dbhydra/src/mongo_db.py,sha256=mP48zRjI7mXKpm45R8prroZI-Eo7JKf0KJqGX-oTy3w,1922
|
|
18
|
-
dbhydra/src/mysql_db.py,sha256=
|
|
18
|
+
dbhydra/src/mysql_db.py,sha256=SgwXV-OVwM9HHeQ83gHht5CF3znOqRSaEZOPIyRdiEY,2800
|
|
19
19
|
dbhydra/src/postgres_db.py,sha256=L7MaBq_6ArwDSP_5LaEqK58oLxZ1X7FgIokcDOSB7wk,1805
|
|
20
20
|
dbhydra/src/sqlserver_db.py,sha256=9Xi3NAliqM79MTV8fpNQb0nWMH8Bqjl1leJSEqgyT94,3611
|
|
21
|
-
dbhydra/src/tables.py,sha256=
|
|
22
|
-
dbhydra/src/xlsx_db.py,sha256=
|
|
21
|
+
dbhydra/src/tables.py,sha256=v-EOdlRp4XwBfticJ0DPumY_FPXwvutYqN9045mMfN0,44246
|
|
22
|
+
dbhydra/src/xlsx_db.py,sha256=Dg-wWafdfa3gSFVdP5Mtn9rNhU4k4R1T0Wx3JyiQZiM,3436
|
|
23
23
|
dbhydra/src/errors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
24
|
dbhydra/src/errors/exceptions.py,sha256=LVpfbTd3NHfQIM-D5TFAU6hOZwGQ3b5DwFD4B6vtf2U,149
|
|
25
25
|
dbhydra/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
26
26
|
dbhydra/tests/test_cases.py,sha256=eAFGaHaIaab3md3HHm2_ryb_HHfObtcXDAEzLh4qWx8,508
|
|
27
27
|
dbhydra/tests/test_mongo.py,sha256=M8TD72M0iQAk7ZcLTWwLmcmmF_zwALnYEGTWjhQlq0s,1979
|
|
28
28
|
dbhydra/tests/test_sql.py,sha256=aPFXyA0jh8o9VG3B5f9fNz7qDbuVPZ9TcE2twn5dAeQ,3126
|
|
29
|
-
dbhydra-2.0.
|
|
30
|
-
dbhydra-2.0.
|
|
31
|
-
dbhydra-2.0.
|
|
32
|
-
dbhydra-2.0.
|
|
33
|
-
dbhydra-2.0.
|
|
29
|
+
dbhydra-2.0.13.dist-info/LICENSE,sha256=k49Yga8CP889JJaHlOpGFzr_be2nqMoep2chYeIDctk,1091
|
|
30
|
+
dbhydra-2.0.13.dist-info/METADATA,sha256=09K_ebuO2xvBibN7gEi1lDm9NGwbruIPoMw-JF0aE5k,2299
|
|
31
|
+
dbhydra-2.0.13.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
|
32
|
+
dbhydra-2.0.13.dist-info/top_level.txt,sha256=oO4Gf1T8_txIsIlp11GI0k7PtBIMb9GRwb5ObF4MLVg,8
|
|
33
|
+
dbhydra-2.0.13.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|