dbhydra 2.0.11__tar.gz → 2.0.13__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.
Files changed (29) hide show
  1. {dbhydra-2.0.11 → dbhydra-2.0.13}/PKG-INFO +1 -1
  2. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/src/abstract_table.py +6 -2
  3. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/src/mysql_db.py +2 -2
  4. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/src/tables.py +33 -0
  5. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/src/xlsx_db.py +16 -0
  6. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra.egg-info/PKG-INFO +1 -1
  7. {dbhydra-2.0.11 → dbhydra-2.0.13}/setup.py +1 -1
  8. {dbhydra-2.0.11 → dbhydra-2.0.13}/LICENSE +0 -0
  9. {dbhydra-2.0.11 → dbhydra-2.0.13}/README.md +0 -0
  10. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/__init__.py +0 -0
  11. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/dbhydra_core.py +0 -0
  12. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/src/__init__.py +0 -0
  13. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/src/abstract_db.py +0 -0
  14. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/src/bigquery_db.py +0 -0
  15. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/src/errors/__init__.py +0 -0
  16. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/src/errors/exceptions.py +0 -0
  17. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/src/migrator.py +0 -0
  18. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/src/mongo_db.py +0 -0
  19. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/src/postgres_db.py +0 -0
  20. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/src/sqlserver_db.py +0 -0
  21. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/tests/__init__.py +0 -0
  22. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/tests/test_cases.py +0 -0
  23. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/tests/test_mongo.py +0 -0
  24. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra/tests/test_sql.py +0 -0
  25. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra.egg-info/SOURCES.txt +0 -0
  26. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra.egg-info/dependency_links.txt +0 -0
  27. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra.egg-info/requires.txt +0 -0
  28. {dbhydra-2.0.11 → dbhydra-2.0.13}/dbhydra.egg-info/top_level.txt +0 -0
  29. {dbhydra-2.0.11 → dbhydra-2.0.13}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dbhydra
3
- Version: 2.0.11
3
+ Version: 2.0.13
4
4
  Summary: Data science friendly ORM combining Python
5
5
  Home-page: https://github.com/DovaX/dbhydra
6
6
  Author: DovaX
@@ -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
- assert len(self.columns) == len(self.types)
242
- self.column_type_dict={self.columns[i]:self.types[i] for i,x in enumerate(self.columns)}
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
@@ -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
 
@@ -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)
@@ -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):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dbhydra
3
- Version: 2.0.11
3
+ Version: 2.0.13
4
4
  Summary: Data science friendly ORM combining Python
5
5
  Home-page: https://github.com/DovaX/dbhydra
6
6
  Author: DovaX
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name='dbhydra',
8
- version='2.0.11',
8
+ version='2.0.13',
9
9
  author='DovaX',
10
10
  author_email='dovax.ai@gmail.com',
11
11
  description='Data science friendly ORM combining Python',
File without changes
File without changes
File without changes
File without changes