thoth-dbmanager 0.4.0__py3-none-any.whl → 0.4.2__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.
Files changed (43) hide show
  1. thoth_dbmanager/ThothDbManager.py +459 -0
  2. thoth_dbmanager/__init__.py +136 -0
  3. thoth_dbmanager/adapters/__init__.py +21 -0
  4. thoth_dbmanager/adapters/mariadb.py +165 -0
  5. thoth_dbmanager/adapters/mysql.py +165 -0
  6. thoth_dbmanager/adapters/oracle.py +554 -0
  7. thoth_dbmanager/adapters/postgresql.py +444 -0
  8. thoth_dbmanager/adapters/qdrant.py +189 -0
  9. thoth_dbmanager/adapters/sqlite.py +385 -0
  10. thoth_dbmanager/adapters/sqlserver.py +583 -0
  11. thoth_dbmanager/adapters/supabase.py +249 -0
  12. thoth_dbmanager/core/__init__.py +13 -0
  13. thoth_dbmanager/core/factory.py +272 -0
  14. thoth_dbmanager/core/interfaces.py +271 -0
  15. thoth_dbmanager/core/registry.py +220 -0
  16. thoth_dbmanager/documents.py +155 -0
  17. thoth_dbmanager/dynamic_imports.py +250 -0
  18. thoth_dbmanager/helpers/__init__.py +0 -0
  19. thoth_dbmanager/helpers/multi_db_generator.py +508 -0
  20. thoth_dbmanager/helpers/preprocess_values.py +159 -0
  21. thoth_dbmanager/helpers/schema.py +376 -0
  22. thoth_dbmanager/helpers/search.py +117 -0
  23. thoth_dbmanager/lsh/__init__.py +21 -0
  24. thoth_dbmanager/lsh/core.py +182 -0
  25. thoth_dbmanager/lsh/factory.py +76 -0
  26. thoth_dbmanager/lsh/manager.py +170 -0
  27. thoth_dbmanager/lsh/storage.py +96 -0
  28. thoth_dbmanager/plugins/__init__.py +23 -0
  29. thoth_dbmanager/plugins/mariadb.py +436 -0
  30. thoth_dbmanager/plugins/mysql.py +408 -0
  31. thoth_dbmanager/plugins/oracle.py +150 -0
  32. thoth_dbmanager/plugins/postgresql.py +145 -0
  33. thoth_dbmanager/plugins/qdrant.py +41 -0
  34. thoth_dbmanager/plugins/sqlite.py +170 -0
  35. thoth_dbmanager/plugins/sqlserver.py +149 -0
  36. thoth_dbmanager/plugins/supabase.py +224 -0
  37. {thoth_dbmanager-0.4.0.dist-info → thoth_dbmanager-0.4.2.dist-info}/METADATA +9 -6
  38. thoth_dbmanager-0.4.2.dist-info/RECORD +41 -0
  39. thoth_dbmanager-0.4.2.dist-info/top_level.txt +1 -0
  40. thoth_dbmanager-0.4.0.dist-info/RECORD +0 -5
  41. thoth_dbmanager-0.4.0.dist-info/top_level.txt +0 -1
  42. {thoth_dbmanager-0.4.0.dist-info → thoth_dbmanager-0.4.2.dist-info}/WHEEL +0 -0
  43. {thoth_dbmanager-0.4.0.dist-info → thoth_dbmanager-0.4.2.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,224 @@
1
+ """
2
+ Supabase plugin implementation.
3
+ """
4
+ import logging
5
+ from typing import Any, Dict, List
6
+ from pathlib import Path
7
+ from urllib.parse import urlparse
8
+
9
+ from ..core.interfaces import DbPlugin, DbAdapter
10
+ from ..core.registry import register_plugin
11
+ from ..adapters.supabase import SupabaseAdapter
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ @register_plugin("supabase")
17
+ class SupabasePlugin(DbPlugin):
18
+ """
19
+ Supabase database plugin implementation.
20
+ Extends PostgreSQL functionality with Supabase-specific features.
21
+ """
22
+
23
+ plugin_name = "Supabase Plugin"
24
+ plugin_version = "1.0.0"
25
+ supported_db_types = ["supabase", "supabase-postgresql"]
26
+ required_dependencies = ["psycopg2-binary", "SQLAlchemy", "supabase", "postgrest-py"]
27
+
28
+ def __init__(self, db_root_path: str, db_mode: str = "dev", **kwargs):
29
+ super().__init__(db_root_path, db_mode, **kwargs)
30
+ self.db_id = None
31
+ self.db_directory_path = None
32
+ self.project_url = None
33
+ self.api_key = None
34
+
35
+ # LSH manager integration (for backward compatibility)
36
+ self._lsh_manager = None
37
+
38
+ def create_adapter(self, **kwargs) -> DbAdapter:
39
+ """Create and return a Supabase adapter instance"""
40
+ return SupabaseAdapter(kwargs)
41
+
42
+ def validate_connection_params(self, **kwargs) -> bool:
43
+ """Validate connection parameters for Supabase"""
44
+ # Support both direct database connection and REST API connection
45
+ use_rest_api = kwargs.get('use_rest_api', False)
46
+
47
+ if use_rest_api:
48
+ return self._validate_rest_params(**kwargs)
49
+ else:
50
+ return self._validate_direct_params(**kwargs)
51
+
52
+ def _validate_rest_params(self, **kwargs) -> bool:
53
+ """Validate REST API connection parameters"""
54
+ required_params = ['project_url', 'api_key']
55
+
56
+ for param in required_params:
57
+ if param not in kwargs:
58
+ logger.error(f"Missing required parameter for REST API: {param}")
59
+ return False
60
+
61
+ # Validate project URL format
62
+ project_url = kwargs.get('project_url')
63
+ try:
64
+ parsed = urlparse(project_url)
65
+ if not parsed.netloc.endswith('.supabase.co'):
66
+ logger.error("Invalid Supabase project URL format")
67
+ return False
68
+ except Exception:
69
+ logger.error("Invalid project URL format")
70
+ return False
71
+
72
+ # Validate API key format
73
+ api_key = kwargs.get('api_key')
74
+ if not api_key or not isinstance(api_key, str):
75
+ logger.error("API key must be a non-empty string")
76
+ return False
77
+
78
+ return True
79
+
80
+ def _validate_direct_params(self, **kwargs) -> bool:
81
+ """Validate direct database connection parameters"""
82
+ required_params = ['host', 'port', 'database', 'user', 'password']
83
+
84
+ for param in required_params:
85
+ if param not in kwargs:
86
+ logger.error(f"Missing required parameter: {param}")
87
+ return False
88
+
89
+ # Validate types
90
+ try:
91
+ port = int(kwargs['port'])
92
+ if port <= 0 or port > 65535:
93
+ logger.error(f"Invalid port number: {port}")
94
+ return False
95
+ except (ValueError, TypeError):
96
+ logger.error(f"Port must be a valid integer: {kwargs.get('port')}")
97
+ return False
98
+
99
+ # Validate required string parameters are not empty
100
+ string_params = ['host', 'database', 'user', 'password']
101
+ for param in string_params:
102
+ if not kwargs.get(param) or not isinstance(kwargs[param], str):
103
+ logger.error(f"Parameter {param} must be a non-empty string")
104
+ return False
105
+
106
+ # Validate SSL parameters if provided
107
+ ssl_params = ['sslcert', 'sslkey', 'sslrootcert']
108
+ for param in ssl_params:
109
+ if param in kwargs and kwargs[param]:
110
+ if not isinstance(kwargs[param], str):
111
+ logger.error(f"SSL parameter {param} must be a string")
112
+ return False
113
+
114
+ return True
115
+
116
+ def initialize(self, **kwargs) -> None:
117
+ """Initialize the Supabase plugin"""
118
+ super().initialize(**kwargs)
119
+
120
+ # Store connection parameters
121
+ self.project_url = kwargs.get('project_url')
122
+ self.api_key = kwargs.get('api_key')
123
+
124
+ # Set up database directory path (for LSH and other features)
125
+ if 'database' in kwargs:
126
+ self.db_id = kwargs['database']
127
+ elif 'project_url' in kwargs:
128
+ # Extract database name from project URL
129
+ parsed = urlparse(kwargs['project_url'])
130
+ self.db_id = parsed.netloc.split('.')[0]
131
+
132
+ if self.db_id:
133
+ self._setup_directory_path(self.db_id)
134
+
135
+ logger.info(f"Supabase plugin initialized for project: {self.db_id}")
136
+
137
+ def _setup_directory_path(self, db_id: str) -> None:
138
+ """Set up the database directory path"""
139
+ if isinstance(self.db_root_path, str):
140
+ self.db_root_path = Path(self.db_root_path)
141
+
142
+ self.db_directory_path = Path(self.db_root_path) / f"{self.db_mode}_databases" / db_id
143
+ self.db_id = db_id
144
+
145
+ # Reset LSH manager when directory path changes
146
+ self._lsh_manager = None
147
+
148
+ @property
149
+ def lsh_manager(self):
150
+ """Lazy load LSH manager for backward compatibility"""
151
+ if self._lsh_manager is None and self.db_directory_path:
152
+ from ..lsh.manager import LshManager
153
+ self._lsh_manager = LshManager(self.db_directory_path)
154
+ return self._lsh_manager
155
+
156
+ # LSH integration methods for backward compatibility
157
+ def set_lsh(self) -> str:
158
+ """Set LSH for backward compatibility"""
159
+ try:
160
+ if self.lsh_manager and self.lsh_manager.load_lsh():
161
+ return "success"
162
+ else:
163
+ return "error"
164
+ except Exception as e:
165
+ logger.error(f"Error loading LSH: {e}")
166
+ return "error"
167
+
168
+ def query_lsh(self, keyword: str, signature_size: int = 30, n_gram: int = 3, top_n: int = 10) -> Dict[str, Dict[str, List[str]]]:
169
+ """Query LSH for backward compatibility"""
170
+ if self.lsh_manager:
171
+ try:
172
+ return self.lsh_manager.query(
173
+ keyword=keyword,
174
+ signature_size=signature_size,
175
+ n_gram=n_gram,
176
+ top_n=top_n
177
+ )
178
+ except Exception as e:
179
+ logger.error(f"LSH query failed: {e}")
180
+ raise Exception(f"Error querying LSH for {self.db_id}: {e}")
181
+ else:
182
+ raise Exception(f"LSH not available for {self.db_id}")
183
+
184
+ def get_connection_info(self) -> Dict[str, Any]:
185
+ """Get connection information"""
186
+ base_info = super().get_plugin_info()
187
+
188
+ if self.adapter:
189
+ adapter_info = self.adapter.get_connection_info()
190
+ base_info.update(adapter_info)
191
+
192
+ base_info.update({
193
+ "db_id": self.db_id,
194
+ "db_directory_path": str(self.db_directory_path) if self.db_directory_path else None,
195
+ "lsh_available": self.lsh_manager is not None,
196
+ "project_url": self.project_url,
197
+ "connection_mode": "REST API" if self.connection_params.get('use_rest_api') else "Direct Database"
198
+ })
199
+
200
+ return base_info
201
+
202
+ def get_example_data(self, table_name: str, number_of_rows: int = 30) -> Dict[str, List[Any]]:
203
+ """Get example data through adapter"""
204
+ if self.adapter:
205
+ return self.adapter.get_example_data(table_name, number_of_rows)
206
+ else:
207
+ raise RuntimeError("Plugin not initialized")
208
+
209
+ def get_required_parameters(self) -> Dict[str, Any]:
210
+ """Get required connection parameters for Supabase"""
211
+ use_rest_api = self.connection_params.get('use_rest_api', False)
212
+
213
+ if use_rest_api:
214
+ return {
215
+ "required": ["project_url", "api_key"],
216
+ "optional": ["schema", "timeout", "pool_size"],
217
+ "connection_mode": "REST API"
218
+ }
219
+ else:
220
+ return {
221
+ "required": ["host", "port", "database", "user", "password"],
222
+ "optional": ["schema", "sslmode", "sslcert", "sslkey", "sslrootcert", "pool_size", "connect_timeout"],
223
+ "connection_mode": "Direct Database"
224
+ }
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
- Name: thoth-dbmanager
3
- Version: 0.4.0
2
+ Name: thoth_dbmanager
3
+ Version: 0.4.2
4
4
  Summary: A Python library for managing SQL databases with support for multiple database types, LSH-based similarity search, and a modern plugin architecture.
5
5
  Author-email: Marco Pancotti <mp@tylconsulting.it>
6
6
  License: MIT
7
- Project-URL: Homepage, https://github.com/mptyl/thoth-dbmanager
8
- Project-URL: Bug Tracker, https://github.com/mptyl/thoth-dbmanager/issues
9
- Project-URL: Documentation, https://github.com/mptyl/thoth-dbmanager#readme
10
- Project-URL: Source Code, https://github.com/mptyl/thoth-dbmanager
7
+ Project-URL: Homepage, https://github.com/mptyl/thoth_dbmanager
8
+ Project-URL: Bug Tracker, https://github.com/mptyl/thoth_dbmanager/issues
9
+ Project-URL: Documentation, https://github.com/mptyl/thoth_dbmanager#readme
10
+ Project-URL: Source Code, https://github.com/mptyl/thoth_dbmanager
11
11
  Keywords: database,sql,lsh,similarity-search,orm
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.8
@@ -45,6 +45,8 @@ Requires-Dist: supabase>=2.0.0; extra == "supabase"
45
45
  Requires-Dist: postgrest-py>=0.16.0; extra == "supabase"
46
46
  Requires-Dist: gotrue-py>=2.0.0; extra == "supabase"
47
47
  Provides-Extra: sqlite
48
+ Provides-Extra: qdrant
49
+ Requires-Dist: qdrant-client>=1.7.0; extra == "qdrant"
48
50
  Provides-Extra: all
49
51
  Requires-Dist: psycopg2-binary>=2.9.0; extra == "all"
50
52
  Requires-Dist: mysql-connector-python>=8.0.0; extra == "all"
@@ -55,6 +57,7 @@ Requires-Dist: informixdb>=2.2.0; extra == "all"
55
57
  Requires-Dist: supabase>=2.0.0; extra == "all"
56
58
  Requires-Dist: postgrest-py>=0.16.0; extra == "all"
57
59
  Requires-Dist: gotrue-py>=2.0.0; extra == "all"
60
+ Requires-Dist: qdrant-client>=1.7.0; extra == "all"
58
61
  Provides-Extra: dev
59
62
  Requires-Dist: pytest>=7.0.0; extra == "dev"
60
63
  Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
@@ -0,0 +1,41 @@
1
+ thoth_dbmanager/ThothDbManager.py,sha256=xyPhB6_3Ao3fGb4LjgCe-MvVI_C-9UXxeazra2dhmkI,17846
2
+ thoth_dbmanager/__init__.py,sha256=Aew8n8l8wMPAf9h6xzzOr7mHBS1-ThTT8js1iHKrAvE,3367
3
+ thoth_dbmanager/documents.py,sha256=z-f7zo_CZHqoGM0qHT8-lSUx4NhnMNZTSajpoFtRxn4,5051
4
+ thoth_dbmanager/dynamic_imports.py,sha256=q99hkh-D-Tnz15_pMJRa_e-gcrgOOYLr5QGhqRhXHgI,7939
5
+ thoth_dbmanager/adapters/__init__.py,sha256=tKIMlo9-gbH_cqnqZJ9yw1zQZKUzsV4hljDUNzcoZXg,486
6
+ thoth_dbmanager/adapters/mariadb.py,sha256=LTsf0gORiwqZkd6WtKcOsYLHyDgysxdqNesBscbJwNs,5709
7
+ thoth_dbmanager/adapters/mysql.py,sha256=TrFbxoMMNWbmUcgkKQYOIfsstmMUmuLlGB7R4ZFEIYI,5698
8
+ thoth_dbmanager/adapters/oracle.py,sha256=JSrsgohjz5PbVc8nI188MZ4QGBQls4ieNmwWfAKA7II,21468
9
+ thoth_dbmanager/adapters/postgresql.py,sha256=qxdlxOV7Nvn8U4Lhat50w87Z2S8AzBfmLfEwKfz7dis,17299
10
+ thoth_dbmanager/adapters/qdrant.py,sha256=sL8ldUbAczENb01MmcrkJBKw0dieWPAG2aj97jznj3k,6557
11
+ thoth_dbmanager/adapters/sqlite.py,sha256=RTDszgnAtkE14LKFeoe9lBHgsqXqkmDk6jDCTmVpnoM,14659
12
+ thoth_dbmanager/adapters/sqlserver.py,sha256=V555kUH54Fb1Atow0BfvbSHmoSwGnrB_RJGn718VQSI,23880
13
+ thoth_dbmanager/adapters/supabase.py,sha256=bl2C6LpOpykPF3vIbdNRDk43aXLADzSk0wQuwTcEHZA,10348
14
+ thoth_dbmanager/core/__init__.py,sha256=FlqNW0GZNv1rnwNgyXGzveLqaw0Z90y5AKhR_1DvHBE,269
15
+ thoth_dbmanager/core/factory.py,sha256=sLj8tKI1ADqSlnU5F0NRtHHtpSimnATuwAqUYx5dfxI,9694
16
+ thoth_dbmanager/core/interfaces.py,sha256=x2eHhIIQmrDEnt_0Ll3GicVWVI_rQip_x5k5sNwirFM,9280
17
+ thoth_dbmanager/core/registry.py,sha256=2E9btPrPVnfI4z4JauKVEkN8mp8qy5gIVm3kKxUUD5E,7960
18
+ thoth_dbmanager/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
+ thoth_dbmanager/helpers/multi_db_generator.py,sha256=LOrWEqh-RTVZXPF7vrlF6BmBGh1XC09kM6XkqkFNPQ4,23232
20
+ thoth_dbmanager/helpers/preprocess_values.py,sha256=sKMjD50UL2CZG7-g7KGe3TJQeXmXC7n28LGge8CaP5c,6183
21
+ thoth_dbmanager/helpers/schema.py,sha256=PhHgUxfFe7qUPxdpWQ3YfS593VQjyKtaSKMlChCyLNo,13978
22
+ thoth_dbmanager/helpers/search.py,sha256=k04L7clSPfeQOlq_ifsH3PZ21ZK-rujh_Qy4hWrvSso,3970
23
+ thoth_dbmanager/lsh/__init__.py,sha256=zAUTRuRX4MNc2nU93tTBkT2_IVL7OBkBL0WZPPgO3Ec,555
24
+ thoth_dbmanager/lsh/core.py,sha256=171FqHW7ItAqAPk6g_AoayKTE3Bs1rRZxnt55MJVzjY,6813
25
+ thoth_dbmanager/lsh/factory.py,sha256=2Bpkk-OygjaptZAw1yysxO1cxG3QTxmJ1yFGcXHqX3w,2411
26
+ thoth_dbmanager/lsh/manager.py,sha256=NDKU2re6Xp7cU6pB5EtucZqQgPiT5nyugoUCCIAG29s,5777
27
+ thoth_dbmanager/lsh/storage.py,sha256=Wp1fjVBVE3inRFTAZCxlc6vwZdlKDwY7wCfwfu7P5Xw,3085
28
+ thoth_dbmanager/plugins/__init__.py,sha256=98iKwNiKnFFeJfw0qLGVOrP2Mo2wGPAolsx7R2B3emA,592
29
+ thoth_dbmanager/plugins/mariadb.py,sha256=ElYa4Rexwrofcjcs0UQKan8fZpbU6-n9zghYR9SgRb4,17975
30
+ thoth_dbmanager/plugins/mysql.py,sha256=mbDsIDV2H_BWYANU4JHMsUkxLQICuGtjKTTPbig2Ngs,16546
31
+ thoth_dbmanager/plugins/oracle.py,sha256=k4Yxvz5MdsH3Sfty9lxbhr8igSnHvGbGujz3bLpNcHo,5230
32
+ thoth_dbmanager/plugins/postgresql.py,sha256=GF6k4K0t7-Y08THWJzS0eWJkrQ1e4GfoKIcanC0Z5Ng,5401
33
+ thoth_dbmanager/plugins/qdrant.py,sha256=XWmc4K6ILiwvB1BhyJBBtA7ohRzQmk1MiZ1N7S-YF78,1199
34
+ thoth_dbmanager/plugins/sqlite.py,sha256=esgJqDp2aSu4a32WnmynfFyY9JfW5W8VjNTkaA-hZhM,6402
35
+ thoth_dbmanager/plugins/sqlserver.py,sha256=mMb3F5FmSWV02FZwj-Ult-2TjuyeVA4Fl1iME1dbgLU,5289
36
+ thoth_dbmanager/plugins/supabase.py,sha256=mWlaGAdpywx4-pU4Ffpmn24ze8sg0sM5kc6bFDoeYRg,8645
37
+ thoth_dbmanager-0.4.2.dist-info/licenses/LICENSE,sha256=81-BOzGgwtY1XdYfkwMQB87AkOGXI9OMq0kjNcZA4UE,1071
38
+ thoth_dbmanager-0.4.2.dist-info/METADATA,sha256=iMFzfRMoh0BqUahLBLt2Pny1oA7L6F1tB7iF8W4D9no,12183
39
+ thoth_dbmanager-0.4.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
40
+ thoth_dbmanager-0.4.2.dist-info/top_level.txt,sha256=b9ttxm9RUc0KUCASEKRx6FqoREYJ1-KZWSpNuaM0uQ4,16
41
+ thoth_dbmanager-0.4.2.dist-info/RECORD,,
@@ -0,0 +1 @@
1
+ thoth_dbmanager
@@ -1,5 +0,0 @@
1
- thoth_dbmanager-0.4.0.dist-info/licenses/LICENSE,sha256=81-BOzGgwtY1XdYfkwMQB87AkOGXI9OMq0kjNcZA4UE,1071
2
- thoth_dbmanager-0.4.0.dist-info/METADATA,sha256=oWkABO_DVnwtvyZIHUzy8PwWiBF3WWk7e3anrY4VxIE,12053
3
- thoth_dbmanager-0.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
4
- thoth_dbmanager-0.4.0.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
5
- thoth_dbmanager-0.4.0.dist-info/RECORD,,
@@ -1 +0,0 @@
1
-