SQLPyHelper 0.2.0__tar.gz → 0.2.1__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.
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/PKG-INFO +1 -1
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/SQLPyHelper.egg-info/PKG-INFO +1 -1
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/setup.py +1 -1
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/sqlpyhelper/__init__.py +1 -1
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/sqlpyhelper/async_helper.py +4 -4
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/sqlpyhelper/db_helper.py +6 -6
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/sqlpyhelper/migration.py +6 -6
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/LICENSE +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/README.md +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/SQLPyHelper.egg-info/SOURCES.txt +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/SQLPyHelper.egg-info/dependency_links.txt +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/SQLPyHelper.egg-info/entry_points.txt +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/SQLPyHelper.egg-info/requires.txt +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/SQLPyHelper.egg-info/top_level.txt +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/pyproject.toml +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/setup.cfg +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/sqlpyhelper/automation_utils.py +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/sqlpyhelper/cli.py +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/sqlpyhelper/py.typed +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/test/test_async_helper.py +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/test/test_migration.py +0 -0
- {sqlpyhelper-0.2.0 → sqlpyhelper-0.2.1}/test/test_sqlpyhelper.py +0 -0
|
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as f:
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name='SQLPyHelper',
|
|
8
|
-
version='0.2.
|
|
8
|
+
version='0.2.1',
|
|
9
9
|
description='A simple SQL database helper package for Python.',
|
|
10
10
|
long_description=long_description,
|
|
11
11
|
long_description_content_type="text/markdown",
|
|
@@ -28,7 +28,7 @@ Example usage::
|
|
|
28
28
|
|
|
29
29
|
import logging
|
|
30
30
|
import os
|
|
31
|
-
from typing import Any, Optional
|
|
31
|
+
from typing import Any, List, Optional, Tuple
|
|
32
32
|
|
|
33
33
|
from dotenv import load_dotenv
|
|
34
34
|
|
|
@@ -190,7 +190,7 @@ class AsyncSQLPyHelper:
|
|
|
190
190
|
"No active connection. Call connect() or use async with."
|
|
191
191
|
)
|
|
192
192
|
|
|
193
|
-
def _adapt_query(self, query: str, args: tuple) ->
|
|
193
|
+
def _adapt_query(self, query: str, args: tuple) -> Tuple[str, tuple]:
|
|
194
194
|
"""
|
|
195
195
|
Adapt a query and its arguments for the active database driver.
|
|
196
196
|
|
|
@@ -320,7 +320,7 @@ class AsyncSQLPyHelper:
|
|
|
320
320
|
except Exception as e:
|
|
321
321
|
raise AsyncQueryError(f"fetch_one failed: {e}") from e
|
|
322
322
|
|
|
323
|
-
async def fetch_all(self, query: str, *args: Any) ->
|
|
323
|
+
async def fetch_all(self, query: str, *args: Any) -> List[Any]:
|
|
324
324
|
"""
|
|
325
325
|
Execute a SELECT query and return all rows.
|
|
326
326
|
|
|
@@ -409,7 +409,7 @@ class AsyncSQLPyHelper:
|
|
|
409
409
|
except Exception as e:
|
|
410
410
|
raise AsyncQueryError(f"fetch_val failed: {e}") from e
|
|
411
411
|
|
|
412
|
-
async def execute_many(self, query: str, args_list:
|
|
412
|
+
async def execute_many(self, query: str, args_list: List[tuple]) -> None:
|
|
413
413
|
"""
|
|
414
414
|
Execute a SQL statement multiple times with different parameters.
|
|
415
415
|
Efficient for bulk inserts::
|
|
@@ -2,7 +2,7 @@ import csv
|
|
|
2
2
|
import logging
|
|
3
3
|
import os
|
|
4
4
|
import re
|
|
5
|
-
from typing import Any, Literal, Optional
|
|
5
|
+
from typing import Any, Dict, List, Literal, Optional
|
|
6
6
|
|
|
7
7
|
from dotenv import load_dotenv
|
|
8
8
|
|
|
@@ -162,7 +162,7 @@ class SQLPyHelper:
|
|
|
162
162
|
except Exception as e:
|
|
163
163
|
raise QueryError(f"Failed to fetch row: {e}") from e
|
|
164
164
|
|
|
165
|
-
def fetch_all(self) ->
|
|
165
|
+
def fetch_all(self) -> List[tuple]:
|
|
166
166
|
"""Fetches all rows from the last executed query"""
|
|
167
167
|
try:
|
|
168
168
|
return self.cursor.fetchall()
|
|
@@ -171,7 +171,7 @@ class SQLPyHelper:
|
|
|
171
171
|
|
|
172
172
|
def fetch_by_param(
|
|
173
173
|
self, table_name: str, column_name: str, value: Any
|
|
174
|
-
) ->
|
|
174
|
+
) -> List[tuple]:
|
|
175
175
|
"""Fetches rows from a table where a column matches the given value."""
|
|
176
176
|
try:
|
|
177
177
|
table_name = _validate_identifier(table_name)
|
|
@@ -191,7 +191,7 @@ class SQLPyHelper:
|
|
|
191
191
|
except Exception as e:
|
|
192
192
|
raise ConnectionError(f"Failed to close connection: {e}") from e
|
|
193
193
|
|
|
194
|
-
def create_table(self, table_name: str, columns:
|
|
194
|
+
def create_table(self, table_name: str, columns: Dict[str, str]) -> None:
|
|
195
195
|
"""
|
|
196
196
|
Creates a table dynamically using a dictionary format.
|
|
197
197
|
Example:
|
|
@@ -210,7 +210,7 @@ class SQLPyHelper:
|
|
|
210
210
|
except Exception as e:
|
|
211
211
|
raise QueryError(f"Failed to create table: {e}") from e
|
|
212
212
|
|
|
213
|
-
def insert_bulk(self, table_name: str, data:
|
|
213
|
+
def insert_bulk(self, table_name: str, data: List[Dict[str, Any]]) -> None:
|
|
214
214
|
"""
|
|
215
215
|
Inserts multiple rows at once.
|
|
216
216
|
Example:
|
|
@@ -374,7 +374,7 @@ class SQLPyHelper:
|
|
|
374
374
|
except Exception as e:
|
|
375
375
|
raise QueryError(f"Failed to rollback transaction: {e}") from e
|
|
376
376
|
|
|
377
|
-
def insert_dynamic(self, table: str, data:
|
|
377
|
+
def insert_dynamic(self, table: str, data: Dict[str, Any]) -> None:
|
|
378
378
|
"""
|
|
379
379
|
Dynamically constructs and executes an INSERT query with database-specific placeholders.
|
|
380
380
|
"""
|
|
@@ -24,7 +24,7 @@ Example usage::
|
|
|
24
24
|
"""
|
|
25
25
|
|
|
26
26
|
import logging
|
|
27
|
-
from typing import Any, Optional
|
|
27
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
28
28
|
|
|
29
29
|
logger = logging.getLogger("sqlpyhelper.migration")
|
|
30
30
|
|
|
@@ -41,7 +41,7 @@ class MigrationError(Exception):
|
|
|
41
41
|
# Generic types are normalised from the source cursor description.
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
_TYPE_MAP:
|
|
44
|
+
_TYPE_MAP: Dict[str, Dict[str, str]] = {
|
|
45
45
|
"sqlite": {
|
|
46
46
|
"integer": "INTEGER",
|
|
47
47
|
"real": "REAL",
|
|
@@ -149,7 +149,7 @@ def _map_type(raw_type: Optional[str], target_db: str) -> str:
|
|
|
149
149
|
return target_types.get(generic, "TEXT")
|
|
150
150
|
|
|
151
151
|
|
|
152
|
-
def _get_column_info(source: Any, table: str) ->
|
|
152
|
+
def _get_column_info(source: Any, table: str) -> List[Tuple[str, str]]:
|
|
153
153
|
"""
|
|
154
154
|
Return a list of (column_name, raw_type_string) tuples
|
|
155
155
|
by inspecting the source database schema.
|
|
@@ -216,7 +216,7 @@ def _get_column_info(source: Any, table: str) -> list[tuple[str, str]]:
|
|
|
216
216
|
|
|
217
217
|
def _build_create_table_sql(
|
|
218
218
|
table: str,
|
|
219
|
-
columns:
|
|
219
|
+
columns: List[Tuple[str, str]],
|
|
220
220
|
target_db: str,
|
|
221
221
|
) -> str:
|
|
222
222
|
"""Build a CREATE TABLE IF NOT EXISTS statement for the target database."""
|
|
@@ -228,7 +228,7 @@ def _build_create_table_sql(
|
|
|
228
228
|
|
|
229
229
|
def _build_insert_sql(
|
|
230
230
|
table: str,
|
|
231
|
-
column_names:
|
|
231
|
+
column_names: List[str],
|
|
232
232
|
target_db: str,
|
|
233
233
|
) -> str:
|
|
234
234
|
"""Build a parameterised INSERT statement for the target database."""
|
|
@@ -250,7 +250,7 @@ def migrate_table(
|
|
|
250
250
|
create_table: bool = True,
|
|
251
251
|
batch_size: int = 500,
|
|
252
252
|
truncate_target: bool = False,
|
|
253
|
-
) ->
|
|
253
|
+
) -> Dict[str, Any]:
|
|
254
254
|
"""
|
|
255
255
|
Migrate a table from one database to another.
|
|
256
256
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|