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.
- thoth_dbmanager/ThothDbManager.py +459 -0
- thoth_dbmanager/__init__.py +136 -0
- thoth_dbmanager/adapters/__init__.py +21 -0
- thoth_dbmanager/adapters/mariadb.py +165 -0
- thoth_dbmanager/adapters/mysql.py +165 -0
- thoth_dbmanager/adapters/oracle.py +554 -0
- thoth_dbmanager/adapters/postgresql.py +444 -0
- thoth_dbmanager/adapters/qdrant.py +189 -0
- thoth_dbmanager/adapters/sqlite.py +385 -0
- thoth_dbmanager/adapters/sqlserver.py +583 -0
- thoth_dbmanager/adapters/supabase.py +249 -0
- thoth_dbmanager/core/__init__.py +13 -0
- thoth_dbmanager/core/factory.py +272 -0
- thoth_dbmanager/core/interfaces.py +271 -0
- thoth_dbmanager/core/registry.py +220 -0
- thoth_dbmanager/documents.py +155 -0
- thoth_dbmanager/dynamic_imports.py +250 -0
- thoth_dbmanager/helpers/__init__.py +0 -0
- thoth_dbmanager/helpers/multi_db_generator.py +508 -0
- thoth_dbmanager/helpers/preprocess_values.py +159 -0
- thoth_dbmanager/helpers/schema.py +376 -0
- thoth_dbmanager/helpers/search.py +117 -0
- thoth_dbmanager/lsh/__init__.py +21 -0
- thoth_dbmanager/lsh/core.py +182 -0
- thoth_dbmanager/lsh/factory.py +76 -0
- thoth_dbmanager/lsh/manager.py +170 -0
- thoth_dbmanager/lsh/storage.py +96 -0
- thoth_dbmanager/plugins/__init__.py +23 -0
- thoth_dbmanager/plugins/mariadb.py +436 -0
- thoth_dbmanager/plugins/mysql.py +408 -0
- thoth_dbmanager/plugins/oracle.py +150 -0
- thoth_dbmanager/plugins/postgresql.py +145 -0
- thoth_dbmanager/plugins/qdrant.py +41 -0
- thoth_dbmanager/plugins/sqlite.py +170 -0
- thoth_dbmanager/plugins/sqlserver.py +149 -0
- thoth_dbmanager/plugins/supabase.py +224 -0
- {thoth_dbmanager-0.4.0.dist-info → thoth_dbmanager-0.4.2.dist-info}/METADATA +9 -6
- thoth_dbmanager-0.4.2.dist-info/RECORD +41 -0
- thoth_dbmanager-0.4.2.dist-info/top_level.txt +1 -0
- thoth_dbmanager-0.4.0.dist-info/RECORD +0 -5
- thoth_dbmanager-0.4.0.dist-info/top_level.txt +0 -1
- {thoth_dbmanager-0.4.0.dist-info → thoth_dbmanager-0.4.2.dist-info}/WHEEL +0 -0
- {thoth_dbmanager-0.4.0.dist-info → thoth_dbmanager-0.4.2.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,250 @@
|
|
1
|
+
"""
|
2
|
+
Dynamic import system for database-specific functionality.
|
3
|
+
This module provides lazy loading of database managers and adapters.
|
4
|
+
"""
|
5
|
+
|
6
|
+
import importlib
|
7
|
+
from typing import Dict, Any, Optional, List
|
8
|
+
import warnings
|
9
|
+
|
10
|
+
# Mapping of database names to their required packages
|
11
|
+
DATABASE_DEPENDENCIES = {
|
12
|
+
'postgresql': ['psycopg2'],
|
13
|
+
'mysql': ['mysql.connector'],
|
14
|
+
'mariadb': ['mariadb'],
|
15
|
+
'sqlserver': ['pyodbc'],
|
16
|
+
'oracle': ['cx_Oracle'],
|
17
|
+
'informix': ['informixdb'],
|
18
|
+
'supabase': ['supabase', 'postgrest', 'gotrue'],
|
19
|
+
'sqlite': [], # Built into Python
|
20
|
+
}
|
21
|
+
|
22
|
+
# Mapping of database names to their manager classes
|
23
|
+
DATABASE_MANAGERS = {
|
24
|
+
'postgresql': 'dbmanager.impl.ThothPgManager.ThothPgManager',
|
25
|
+
'mysql': 'dbmanager.impl.ThothMySqlManager.ThothMySqlManager',
|
26
|
+
'mariadb': 'dbmanager.impl.ThothMariaDbManager.ThothMariaDbManager',
|
27
|
+
'sqlserver': 'dbmanager.impl.ThothSqlServerManager.ThothSqlServerManager',
|
28
|
+
'oracle': 'dbmanager.impl.ThothOracleManager.ThothOracleManager',
|
29
|
+
'informix': 'dbmanager.impl.ThothInformixManager.ThothInformixManager',
|
30
|
+
'supabase': 'dbmanager.impl.ThothSupabaseManager.ThothSupabaseManager',
|
31
|
+
'sqlite': 'dbmanager.impl.ThothSqliteManager.ThothSqliteManager',
|
32
|
+
}
|
33
|
+
|
34
|
+
# Mapping of database names to their adapter classes
|
35
|
+
DATABASE_ADAPTERS = {
|
36
|
+
'postgresql': 'dbmanager.adapters.postgresql.PostgreSQLAdapter',
|
37
|
+
'mysql': 'dbmanager.adapters.mysql.MySQLAdapter',
|
38
|
+
'mariadb': 'dbmanager.adapters.mariadb.MariaDBAdapter',
|
39
|
+
'sqlserver': 'dbmanager.adapters.sqlserver.SQLServerAdapter',
|
40
|
+
'oracle': 'dbmanager.adapters.oracle.OracleAdapter',
|
41
|
+
'informix': 'dbmanager.adapters.informix.InformixAdapter',
|
42
|
+
'supabase': 'dbmanager.adapters.supabase.SupabaseAdapter',
|
43
|
+
'sqlite': 'dbmanager.adapters.sqlite.SQLiteAdapter',
|
44
|
+
}
|
45
|
+
|
46
|
+
# Mapping of database names to their plugin classes
|
47
|
+
DATABASE_PLUGINS = {
|
48
|
+
'postgresql': 'dbmanager.plugins.postgresql.PostgreSQLPlugin',
|
49
|
+
'mysql': 'dbmanager.plugins.mysql.MySQLPlugin',
|
50
|
+
'mariadb': 'dbmanager.plugins.mariadb.MariaDBPlugin',
|
51
|
+
'sqlserver': 'dbmanager.plugins.sqlserver.SQLServerPlugin',
|
52
|
+
'oracle': 'dbmanager.plugins.oracle.OraclePlugin',
|
53
|
+
'informix': 'dbmanager.plugins.informix.InformixPlugin',
|
54
|
+
'supabase': 'dbmanager.plugins.supabase.SupabasePlugin',
|
55
|
+
'sqlite': 'dbmanager.plugins.sqlite.SQLitePlugin',
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
class DatabaseImportError(ImportError):
|
60
|
+
"""Custom exception for database import errors."""
|
61
|
+
|
62
|
+
def __init__(self, database: str, missing_deps: List[str]):
|
63
|
+
self.database = database
|
64
|
+
self.missing_deps = missing_deps
|
65
|
+
super().__init__(
|
66
|
+
f"Missing dependencies for {database}: {', '.join(missing_deps)}. "
|
67
|
+
f"Install with: pip install thoth-sqldb[{database}]"
|
68
|
+
)
|
69
|
+
|
70
|
+
|
71
|
+
def check_dependencies(database: str) -> List[str]:
|
72
|
+
"""
|
73
|
+
Check if required dependencies for a database are available.
|
74
|
+
|
75
|
+
Args:
|
76
|
+
database: Name of the database
|
77
|
+
|
78
|
+
Returns:
|
79
|
+
List of missing dependency names
|
80
|
+
"""
|
81
|
+
if database not in DATABASE_DEPENDENCIES:
|
82
|
+
raise ValueError(f"Unknown database: {database}")
|
83
|
+
|
84
|
+
missing_deps = []
|
85
|
+
for dep in DATABASE_DEPENDENCIES[database]:
|
86
|
+
try:
|
87
|
+
importlib.import_module(dep)
|
88
|
+
except ImportError:
|
89
|
+
missing_deps.append(dep)
|
90
|
+
|
91
|
+
return missing_deps
|
92
|
+
|
93
|
+
|
94
|
+
def import_manager(database: str) -> Any:
|
95
|
+
"""
|
96
|
+
Dynamically import a database manager class.
|
97
|
+
|
98
|
+
Args:
|
99
|
+
database: Name of the database
|
100
|
+
|
101
|
+
Returns:
|
102
|
+
The database manager class
|
103
|
+
|
104
|
+
Raises:
|
105
|
+
DatabaseImportError: If dependencies are missing
|
106
|
+
ImportError: If the manager class cannot be imported
|
107
|
+
"""
|
108
|
+
if database not in DATABASE_MANAGERS:
|
109
|
+
raise ValueError(f"Unknown database: {database}")
|
110
|
+
|
111
|
+
# Check dependencies
|
112
|
+
missing_deps = check_dependencies(database)
|
113
|
+
if missing_deps:
|
114
|
+
raise DatabaseImportError(database, missing_deps)
|
115
|
+
|
116
|
+
# Import the manager class
|
117
|
+
module_path, class_name = DATABASE_MANAGERS[database].rsplit('.', 1)
|
118
|
+
module = importlib.import_module(module_path)
|
119
|
+
return getattr(module, class_name)
|
120
|
+
|
121
|
+
|
122
|
+
def import_adapter(database: str) -> Any:
|
123
|
+
"""
|
124
|
+
Dynamically import a database adapter class.
|
125
|
+
|
126
|
+
Args:
|
127
|
+
database: Name of the database
|
128
|
+
|
129
|
+
Returns:
|
130
|
+
The database adapter class
|
131
|
+
|
132
|
+
Raises:
|
133
|
+
DatabaseImportError: If dependencies are missing
|
134
|
+
ImportError: If the adapter class cannot be imported
|
135
|
+
"""
|
136
|
+
if database not in DATABASE_ADAPTERS:
|
137
|
+
raise ValueError(f"Unknown database: {database}")
|
138
|
+
|
139
|
+
# Check dependencies
|
140
|
+
missing_deps = check_dependencies(database)
|
141
|
+
if missing_deps:
|
142
|
+
raise DatabaseImportError(database, missing_deps)
|
143
|
+
|
144
|
+
# Import the adapter class
|
145
|
+
module_path, class_name = DATABASE_ADAPTERS[database].rsplit('.', 1)
|
146
|
+
module = importlib.import_module(module_path)
|
147
|
+
return getattr(module, class_name)
|
148
|
+
|
149
|
+
|
150
|
+
def import_plugin(database: str) -> Any:
|
151
|
+
"""
|
152
|
+
Dynamically import a database plugin class.
|
153
|
+
|
154
|
+
Args:
|
155
|
+
database: Name of the database
|
156
|
+
|
157
|
+
Returns:
|
158
|
+
The database plugin class
|
159
|
+
|
160
|
+
Raises:
|
161
|
+
DatabaseImportError: If dependencies are missing
|
162
|
+
ImportError: If the plugin class cannot be imported
|
163
|
+
"""
|
164
|
+
if database not in DATABASE_PLUGINS:
|
165
|
+
raise ValueError(f"Unknown database: {database}")
|
166
|
+
|
167
|
+
# Check dependencies
|
168
|
+
missing_deps = check_dependencies(database)
|
169
|
+
if missing_deps:
|
170
|
+
raise DatabaseImportError(database, missing_deps)
|
171
|
+
|
172
|
+
# Import the plugin class
|
173
|
+
module_path, class_name = DATABASE_PLUGINS[database].rsplit('.', 1)
|
174
|
+
module = importlib.import_module(module_path)
|
175
|
+
return getattr(module, class_name)
|
176
|
+
|
177
|
+
|
178
|
+
def get_available_databases() -> Dict[str, bool]:
|
179
|
+
"""
|
180
|
+
Get a dictionary of available databases and their dependency status.
|
181
|
+
|
182
|
+
Returns:
|
183
|
+
Dictionary mapping database names to availability (True if all dependencies are available)
|
184
|
+
"""
|
185
|
+
availability = {}
|
186
|
+
for db in DATABASE_DEPENDENCIES:
|
187
|
+
missing_deps = check_dependencies(db)
|
188
|
+
availability[db] = len(missing_deps) == 0
|
189
|
+
|
190
|
+
return availability
|
191
|
+
|
192
|
+
|
193
|
+
def import_database_components(databases: List[str]) -> Dict[str, Dict[str, Any]]:
|
194
|
+
"""
|
195
|
+
Import components for specified databases.
|
196
|
+
|
197
|
+
Args:
|
198
|
+
databases: List of database names to import
|
199
|
+
|
200
|
+
Returns:
|
201
|
+
Dictionary mapping database names to their components
|
202
|
+
"""
|
203
|
+
components = {}
|
204
|
+
|
205
|
+
for db in databases:
|
206
|
+
try:
|
207
|
+
components[db] = {
|
208
|
+
'manager': import_manager(db),
|
209
|
+
'adapter': import_adapter(db),
|
210
|
+
'plugin': import_plugin(db)
|
211
|
+
}
|
212
|
+
except DatabaseImportError as e:
|
213
|
+
warnings.warn(str(e))
|
214
|
+
components[db] = None
|
215
|
+
|
216
|
+
return components
|
217
|
+
|
218
|
+
|
219
|
+
# Convenience functions for common use cases
|
220
|
+
def import_postgresql():
|
221
|
+
"""Import PostgreSQL components."""
|
222
|
+
return import_database_components(['postgresql'])['postgresql']
|
223
|
+
|
224
|
+
def import_mysql():
|
225
|
+
"""Import MySQL components."""
|
226
|
+
return import_database_components(['mysql'])['mysql']
|
227
|
+
|
228
|
+
def import_sqlite():
|
229
|
+
"""Import SQLite components."""
|
230
|
+
return import_database_components(['sqlite'])['sqlite']
|
231
|
+
|
232
|
+
def import_sqlserver():
|
233
|
+
"""Import SQL Server components."""
|
234
|
+
return import_database_components(['sqlserver'])['sqlserver']
|
235
|
+
|
236
|
+
def import_oracle():
|
237
|
+
"""Import Oracle components."""
|
238
|
+
return import_database_components(['oracle'])['oracle']
|
239
|
+
|
240
|
+
def import_mariadb():
|
241
|
+
"""Import MariaDB components."""
|
242
|
+
return import_database_components(['mariadb'])['mariadb']
|
243
|
+
|
244
|
+
def import_informix():
|
245
|
+
"""Import Informix components."""
|
246
|
+
return import_database_components(['informix'])['informix']
|
247
|
+
|
248
|
+
def import_supabase():
|
249
|
+
"""Import Supabase components."""
|
250
|
+
return import_database_components(['supabase'])['supabase']
|
File without changes
|