thoth-dbmanager 0.5.0__py3-none-any.whl → 0.5.1__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.
@@ -1,150 +0,0 @@
1
- """
2
- Oracle plugin implementation.
3
- """
4
- import logging
5
- from typing import Any, Dict, List
6
- from pathlib import Path
7
-
8
- from ..core.interfaces import DbPlugin, DbAdapter
9
- from ..core.registry import register_plugin
10
- from ..adapters.oracle import OracleAdapter
11
-
12
- logger = logging.getLogger(__name__)
13
-
14
-
15
- @register_plugin("oracle")
16
- class OraclePlugin(DbPlugin):
17
- """
18
- Oracle database plugin implementation.
19
- """
20
-
21
- plugin_name = "Oracle Plugin"
22
- plugin_version = "1.0.0"
23
- supported_db_types = ["oracle"]
24
- required_dependencies = ["cx_Oracle", "SQLAlchemy"]
25
-
26
- def __init__(self, db_root_path: str, db_mode: str = "dev", **kwargs):
27
- super().__init__(db_root_path, db_mode, **kwargs)
28
- self.db_id = None
29
- self.db_directory_path = None
30
-
31
- # LSH manager integration (for backward compatibility)
32
- self._lsh_manager = None
33
-
34
- def create_adapter(self, **kwargs) -> DbAdapter:
35
- """Create and return an Oracle adapter instance"""
36
- return OracleAdapter(kwargs)
37
-
38
- def validate_connection_params(self, **kwargs) -> bool:
39
- """Validate connection parameters for Oracle"""
40
- required_params = ['host', 'port', 'service_name', 'user', 'password']
41
-
42
- for param in required_params:
43
- if param not in kwargs:
44
- logger.error(f"Missing required parameter: {param}")
45
- return False
46
-
47
- # Validate types
48
- try:
49
- port = int(kwargs['port'])
50
- if port <= 0 or port > 65535:
51
- logger.error(f"Invalid port number: {port}")
52
- return False
53
- except (ValueError, TypeError):
54
- logger.error(f"Port must be a valid integer: {kwargs.get('port')}")
55
- return False
56
-
57
- # Validate required string parameters are not empty
58
- string_params = ['host', 'service_name', 'user', 'password']
59
- for param in string_params:
60
- if not kwargs.get(param) or not isinstance(kwargs[param], str):
61
- logger.error(f"Parameter {param} must be a non-empty string")
62
- return False
63
-
64
- return True
65
-
66
- def initialize(self, **kwargs) -> None:
67
- """Initialize the Oracle plugin"""
68
- super().initialize(**kwargs)
69
-
70
- # Set up database directory path (for LSH and other features)
71
- if 'service_name' in kwargs:
72
- self.db_id = kwargs['service_name']
73
- self._setup_directory_path(self.db_id)
74
-
75
- logger.info(f"Oracle plugin initialized for service: {self.db_id}")
76
-
77
- def _setup_directory_path(self, db_id: str) -> None:
78
- """Set up directory path for database-specific files"""
79
- if self.db_root_path:
80
- self.db_directory_path = Path(self.db_root_path) / "oracle" / db_id
81
- self.db_directory_path.mkdir(parents=True, exist_ok=True)
82
-
83
- @property
84
- def lsh_manager(self):
85
- """Get LSH manager (for backward compatibility)"""
86
- return self._lsh_manager
87
-
88
- def get_connection_info(self) -> Dict[str, Any]:
89
- """Get connection information"""
90
- base_info = super().get_plugin_info()
91
-
92
- if self.adapter:
93
- adapter_info = self.adapter.get_connection_info()
94
- base_info.update(adapter_info)
95
-
96
- base_info.update({
97
- "db_id": self.db_id,
98
- "db_directory_path": str(self.db_directory_path) if self.db_directory_path else None,
99
- "lsh_available": self.lsh_manager is not None
100
- })
101
-
102
- return base_info
103
-
104
- def get_example_data(self, table_name: str, number_of_rows: int = 30) -> Dict[str, List[Any]]:
105
- """Get example data through adapter"""
106
- if self.adapter:
107
- return self.adapter.get_example_data(table_name, number_of_rows)
108
- else:
109
- raise RuntimeError("Plugin not initialized")
110
-
111
- def validate_connection_string(self, connection_string: str) -> bool:
112
- """Validate Oracle connection string format."""
113
- return connection_string.startswith("oracle+cx_oracle://")
114
-
115
- def get_database_info(self) -> Dict[str, Any]:
116
- """Get Oracle database information."""
117
- return {
118
- "name": self.name,
119
- "display_name": self.display_name,
120
- "description": self.description,
121
- "version": self.version,
122
- "features": [
123
- "transactions",
124
- "foreign_keys",
125
- "indexes",
126
- "views",
127
- "stored_procedures",
128
- "triggers",
129
- "sequences",
130
- "partitions",
131
- "materialized_views"
132
- ],
133
- "data_types": [
134
- "NUMBER", "BINARY_INTEGER", "PLS_INTEGER",
135
- "VARCHAR2", "NVARCHAR2", "CHAR", "NCHAR", "CLOB", "NCLOB", "BLOB", "BFILE",
136
- "DATE", "TIMESTAMP", "INTERVAL",
137
- "RAW", "LONG", "LONG RAW",
138
- "ROWID", "UROWID"
139
- ]
140
- }
141
-
142
- def get_sample_connection_config(self) -> Dict[str, Any]:
143
- """Get sample connection configuration."""
144
- return {
145
- "host": "localhost",
146
- "port": 1521,
147
- "service_name": "ORCL",
148
- "username": "user",
149
- "password": "password"
150
- }
@@ -1,224 +0,0 @@
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
- }