SQLPyHelper 0.1.8__tar.gz → 0.2.0__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 (22) hide show
  1. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/PKG-INFO +52 -18
  2. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/README.md +51 -17
  3. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/SQLPyHelper.egg-info/PKG-INFO +52 -18
  4. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/setup.py +1 -1
  5. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/sqlpyhelper/__init__.py +1 -1
  6. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/sqlpyhelper/async_helper.py +0 -1
  7. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/sqlpyhelper/db_helper.py +10 -5
  8. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/LICENSE +0 -0
  9. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/SQLPyHelper.egg-info/SOURCES.txt +0 -0
  10. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/SQLPyHelper.egg-info/dependency_links.txt +0 -0
  11. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/SQLPyHelper.egg-info/entry_points.txt +0 -0
  12. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/SQLPyHelper.egg-info/requires.txt +0 -0
  13. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/SQLPyHelper.egg-info/top_level.txt +0 -0
  14. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/pyproject.toml +0 -0
  15. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/setup.cfg +0 -0
  16. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/sqlpyhelper/automation_utils.py +0 -0
  17. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/sqlpyhelper/cli.py +0 -0
  18. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/sqlpyhelper/migration.py +0 -0
  19. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/sqlpyhelper/py.typed +0 -0
  20. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/test/test_async_helper.py +0 -0
  21. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/test/test_migration.py +0 -0
  22. {sqlpyhelper-0.1.8 → sqlpyhelper-0.2.0}/test/test_sqlpyhelper.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SQLPyHelper
3
- Version: 0.1.8
3
+ Version: 0.2.0
4
4
  Summary: A simple SQL database helper package for Python.
5
5
  Home-page: https://github.com/adebayopeter/sqlpyhelper
6
6
  Author: Adebayo Olaonipekun
@@ -101,6 +101,7 @@ with SQLPyHelper(db_type="postgres", host="localhost", user="user",
101
101
  - [MySQL Example](#mysql-example)
102
102
  - [SQL Server Example](#sql-server-example)
103
103
  - [Oracle Example](#oracle-example)
104
+ - [Async Example (FastAPI / asyncio)](#async-example-fastapi--asyncio)
104
105
  - [📂 Project Structure](#-project-structure)
105
106
  - [📌 Available Methods in SQLPyHelper](#-available-methods-in-sqlpyhelper)
106
107
  - [🌍 Contributing](#-contributing)
@@ -108,14 +109,16 @@ with SQLPyHelper(db_type="postgres", host="localhost", user="user",
108
109
 
109
110
  ---
110
111
 
111
- ## 🚀 Features in v0.1.4
112
- - Unified connection pooling for multiple databases.
113
- - Automatic reconnection for lost connections.
114
- - Transaction support (BEGIN, ROLLBACK, COMMIT).
115
- - Secure parameterized queries to prevent SQL injection.
116
- - Bulk insertion & dynamic table creation.
117
- - Logging & error handling for better debugging.
112
+ ## 🚀 Features in v0.1.8
113
+ - Unified connection pooling for multiple databases.
114
+ - Automatic reconnection for lost connections.
115
+ - Transaction support (BEGIN, ROLLBACK, COMMIT).
116
+ - Secure parameterized queries to prevent SQL injection.
117
+ - Bulk insertion & dynamic table creation.
118
+ - Logging & error handling for better debugging.
118
119
  - CSV export & database backups.
120
+ - **Cross-database migration** — copy tables between any two supported databases.
121
+ - **Async support** — `AsyncSQLPyHelper` for FastAPI and asyncio applications.
119
122
 
120
123
  ---
121
124
  ## 📦 Installation
@@ -214,20 +217,50 @@ db.setup_connection_pool(min_conn=2, max_conn=10) # Enable pooling for better p
214
217
  conn = db.get_connection_from_pool()
215
218
  db.return_connection_to_pool(conn)
216
219
  ```
220
+ ### Async Example (FastAPI / asyncio)
221
+ ```python
222
+ import asyncio
223
+ from sqlpyhelper.async_helper import AsyncSQLPyHelper
224
+
225
+ async def main():
226
+ async with AsyncSQLPyHelper(db_type="sqlite", database="my.db") as db:
227
+ await db.execute(
228
+ "CREATE TABLE IF NOT EXISTS users (id INTEGER, name TEXT)"
229
+ )
230
+ await db.execute(
231
+ "INSERT INTO users VALUES ($1, $2)", 1, "Alice"
232
+ )
233
+ rows = await db.fetch_all("SELECT * FROM users")
234
+ print(rows)
235
+
236
+ asyncio.run(main())
237
+ ```
217
238
 
218
239
  ## 📂 Project Structure
219
240
  ```
220
241
  📦 SQLPyHelper/
221
- ├─ sqlpyhelper/
222
-   ├─ __init__.py
223
-   └─ db_helper.py
224
- ├─ tests/
225
-   └─ test_sqlpyhelper.py
226
- ├─ .env_example
227
- ├─ .gitignore
228
- ├─ setup.py
229
- ├─ README.md
230
- └─ requirements.txt
242
+ ├─ sqlpyhelper/
243
+ ├─ __init__.py
244
+ ├─ db_helper.py
245
+ ├─ async_helper.py
246
+ ├─ automation_utils.py
247
+ ├─ cli.py
248
+ │ └─ migration.py
249
+ ├─ test/
250
+ ├─ test_sqlpyhelper.py
251
+ │ ├─ test_async_helper.py
252
+ │ └─ test_migration.py
253
+ ├─ docs/
254
+ ├─ .env_example
255
+ ├─ .gitignore
256
+ ├─ setup.py
257
+ ├─ setup.cfg
258
+ ├─ pyproject.toml
259
+ ├─ CHANGELOG.md
260
+ ├─ CONTRIBUTING.md
261
+ ├─ pre-commit.sh
262
+ ├─ README.md
263
+ └─ requirements.txt
231
264
  ```
232
265
  ---
233
266
  ## 📌 Available Methods in SQLPyHelper
@@ -249,6 +282,7 @@ db.return_connection_to_pool(conn)
249
282
  | `commit_transaction()` | Commits the current transaction. |
250
283
  | `close()` | Closes the database connection safely. |
251
284
  | `__enter__` / `__exit__()` | Use as a context manager — connection closes automatically. |
285
+ | `AsyncSQLPyHelper` | Async-native class for FastAPI/asyncio — see [Async docs](https://sqlpyhelper.readthedocs.io/en/latest/async.html). |
252
286
 
253
287
  ---
254
288
  ## 🌍 Contributing
@@ -29,6 +29,7 @@ with SQLPyHelper(db_type="postgres", host="localhost", user="user",
29
29
  - [MySQL Example](#mysql-example)
30
30
  - [SQL Server Example](#sql-server-example)
31
31
  - [Oracle Example](#oracle-example)
32
+ - [Async Example (FastAPI / asyncio)](#async-example-fastapi--asyncio)
32
33
  - [📂 Project Structure](#-project-structure)
33
34
  - [📌 Available Methods in SQLPyHelper](#-available-methods-in-sqlpyhelper)
34
35
  - [🌍 Contributing](#-contributing)
@@ -36,14 +37,16 @@ with SQLPyHelper(db_type="postgres", host="localhost", user="user",
36
37
 
37
38
  ---
38
39
 
39
- ## 🚀 Features in v0.1.4
40
- - Unified connection pooling for multiple databases.
41
- - Automatic reconnection for lost connections.
42
- - Transaction support (BEGIN, ROLLBACK, COMMIT).
43
- - Secure parameterized queries to prevent SQL injection.
44
- - Bulk insertion & dynamic table creation.
45
- - Logging & error handling for better debugging.
40
+ ## 🚀 Features in v0.1.8
41
+ - Unified connection pooling for multiple databases.
42
+ - Automatic reconnection for lost connections.
43
+ - Transaction support (BEGIN, ROLLBACK, COMMIT).
44
+ - Secure parameterized queries to prevent SQL injection.
45
+ - Bulk insertion & dynamic table creation.
46
+ - Logging & error handling for better debugging.
46
47
  - CSV export & database backups.
48
+ - **Cross-database migration** — copy tables between any two supported databases.
49
+ - **Async support** — `AsyncSQLPyHelper` for FastAPI and asyncio applications.
47
50
 
48
51
  ---
49
52
  ## 📦 Installation
@@ -142,20 +145,50 @@ db.setup_connection_pool(min_conn=2, max_conn=10) # Enable pooling for better p
142
145
  conn = db.get_connection_from_pool()
143
146
  db.return_connection_to_pool(conn)
144
147
  ```
148
+ ### Async Example (FastAPI / asyncio)
149
+ ```python
150
+ import asyncio
151
+ from sqlpyhelper.async_helper import AsyncSQLPyHelper
152
+
153
+ async def main():
154
+ async with AsyncSQLPyHelper(db_type="sqlite", database="my.db") as db:
155
+ await db.execute(
156
+ "CREATE TABLE IF NOT EXISTS users (id INTEGER, name TEXT)"
157
+ )
158
+ await db.execute(
159
+ "INSERT INTO users VALUES ($1, $2)", 1, "Alice"
160
+ )
161
+ rows = await db.fetch_all("SELECT * FROM users")
162
+ print(rows)
163
+
164
+ asyncio.run(main())
165
+ ```
145
166
 
146
167
  ## 📂 Project Structure
147
168
  ```
148
169
  📦 SQLPyHelper/
149
- ├─ sqlpyhelper/
150
-   ├─ __init__.py
151
-   └─ db_helper.py
152
- ├─ tests/
153
-   └─ test_sqlpyhelper.py
154
- ├─ .env_example
155
- ├─ .gitignore
156
- ├─ setup.py
157
- ├─ README.md
158
- └─ requirements.txt
170
+ ├─ sqlpyhelper/
171
+ ├─ __init__.py
172
+ ├─ db_helper.py
173
+ ├─ async_helper.py
174
+ ├─ automation_utils.py
175
+ ├─ cli.py
176
+ │ └─ migration.py
177
+ ├─ test/
178
+ ├─ test_sqlpyhelper.py
179
+ │ ├─ test_async_helper.py
180
+ │ └─ test_migration.py
181
+ ├─ docs/
182
+ ├─ .env_example
183
+ ├─ .gitignore
184
+ ├─ setup.py
185
+ ├─ setup.cfg
186
+ ├─ pyproject.toml
187
+ ├─ CHANGELOG.md
188
+ ├─ CONTRIBUTING.md
189
+ ├─ pre-commit.sh
190
+ ├─ README.md
191
+ └─ requirements.txt
159
192
  ```
160
193
  ---
161
194
  ## 📌 Available Methods in SQLPyHelper
@@ -177,6 +210,7 @@ db.return_connection_to_pool(conn)
177
210
  | `commit_transaction()` | Commits the current transaction. |
178
211
  | `close()` | Closes the database connection safely. |
179
212
  | `__enter__` / `__exit__()` | Use as a context manager — connection closes automatically. |
213
+ | `AsyncSQLPyHelper` | Async-native class for FastAPI/asyncio — see [Async docs](https://sqlpyhelper.readthedocs.io/en/latest/async.html). |
180
214
 
181
215
  ---
182
216
  ## 🌍 Contributing
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SQLPyHelper
3
- Version: 0.1.8
3
+ Version: 0.2.0
4
4
  Summary: A simple SQL database helper package for Python.
5
5
  Home-page: https://github.com/adebayopeter/sqlpyhelper
6
6
  Author: Adebayo Olaonipekun
@@ -101,6 +101,7 @@ with SQLPyHelper(db_type="postgres", host="localhost", user="user",
101
101
  - [MySQL Example](#mysql-example)
102
102
  - [SQL Server Example](#sql-server-example)
103
103
  - [Oracle Example](#oracle-example)
104
+ - [Async Example (FastAPI / asyncio)](#async-example-fastapi--asyncio)
104
105
  - [📂 Project Structure](#-project-structure)
105
106
  - [📌 Available Methods in SQLPyHelper](#-available-methods-in-sqlpyhelper)
106
107
  - [🌍 Contributing](#-contributing)
@@ -108,14 +109,16 @@ with SQLPyHelper(db_type="postgres", host="localhost", user="user",
108
109
 
109
110
  ---
110
111
 
111
- ## 🚀 Features in v0.1.4
112
- - Unified connection pooling for multiple databases.
113
- - Automatic reconnection for lost connections.
114
- - Transaction support (BEGIN, ROLLBACK, COMMIT).
115
- - Secure parameterized queries to prevent SQL injection.
116
- - Bulk insertion & dynamic table creation.
117
- - Logging & error handling for better debugging.
112
+ ## 🚀 Features in v0.1.8
113
+ - Unified connection pooling for multiple databases.
114
+ - Automatic reconnection for lost connections.
115
+ - Transaction support (BEGIN, ROLLBACK, COMMIT).
116
+ - Secure parameterized queries to prevent SQL injection.
117
+ - Bulk insertion & dynamic table creation.
118
+ - Logging & error handling for better debugging.
118
119
  - CSV export & database backups.
120
+ - **Cross-database migration** — copy tables between any two supported databases.
121
+ - **Async support** — `AsyncSQLPyHelper` for FastAPI and asyncio applications.
119
122
 
120
123
  ---
121
124
  ## 📦 Installation
@@ -214,20 +217,50 @@ db.setup_connection_pool(min_conn=2, max_conn=10) # Enable pooling for better p
214
217
  conn = db.get_connection_from_pool()
215
218
  db.return_connection_to_pool(conn)
216
219
  ```
220
+ ### Async Example (FastAPI / asyncio)
221
+ ```python
222
+ import asyncio
223
+ from sqlpyhelper.async_helper import AsyncSQLPyHelper
224
+
225
+ async def main():
226
+ async with AsyncSQLPyHelper(db_type="sqlite", database="my.db") as db:
227
+ await db.execute(
228
+ "CREATE TABLE IF NOT EXISTS users (id INTEGER, name TEXT)"
229
+ )
230
+ await db.execute(
231
+ "INSERT INTO users VALUES ($1, $2)", 1, "Alice"
232
+ )
233
+ rows = await db.fetch_all("SELECT * FROM users")
234
+ print(rows)
235
+
236
+ asyncio.run(main())
237
+ ```
217
238
 
218
239
  ## 📂 Project Structure
219
240
  ```
220
241
  📦 SQLPyHelper/
221
- ├─ sqlpyhelper/
222
-   ├─ __init__.py
223
-   └─ db_helper.py
224
- ├─ tests/
225
-   └─ test_sqlpyhelper.py
226
- ├─ .env_example
227
- ├─ .gitignore
228
- ├─ setup.py
229
- ├─ README.md
230
- └─ requirements.txt
242
+ ├─ sqlpyhelper/
243
+ ├─ __init__.py
244
+ ├─ db_helper.py
245
+ ├─ async_helper.py
246
+ ├─ automation_utils.py
247
+ ├─ cli.py
248
+ │ └─ migration.py
249
+ ├─ test/
250
+ ├─ test_sqlpyhelper.py
251
+ │ ├─ test_async_helper.py
252
+ │ └─ test_migration.py
253
+ ├─ docs/
254
+ ├─ .env_example
255
+ ├─ .gitignore
256
+ ├─ setup.py
257
+ ├─ setup.cfg
258
+ ├─ pyproject.toml
259
+ ├─ CHANGELOG.md
260
+ ├─ CONTRIBUTING.md
261
+ ├─ pre-commit.sh
262
+ ├─ README.md
263
+ └─ requirements.txt
231
264
  ```
232
265
  ---
233
266
  ## 📌 Available Methods in SQLPyHelper
@@ -249,6 +282,7 @@ db.return_connection_to_pool(conn)
249
282
  | `commit_transaction()` | Commits the current transaction. |
250
283
  | `close()` | Closes the database connection safely. |
251
284
  | `__enter__` / `__exit__()` | Use as a context manager — connection closes automatically. |
285
+ | `AsyncSQLPyHelper` | Async-native class for FastAPI/asyncio — see [Async docs](https://sqlpyhelper.readthedocs.io/en/latest/async.html). |
252
286
 
253
287
  ---
254
288
  ## 🌍 Contributing
@@ -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.1.8',
8
+ version='0.2.0',
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",
@@ -1,5 +1,5 @@
1
1
  # Match the version in setup.py
2
- __version__ = "0.1.8"
2
+ __version__ = "0.2.0"
3
3
 
4
4
  from sqlpyhelper.async_helper import ( # noqa: F401
5
5
  AsyncConnectionError,
@@ -105,7 +105,6 @@ class AsyncSQLPyHelper:
105
105
  import aiosqlite
106
106
 
107
107
  self._connection = await aiosqlite.connect(self.database or "") # type: ignore[arg-type]
108
- self._connection.row_factory = aiosqlite.Row
109
108
  logger.info("Connected to SQLite database: %s", self.database)
110
109
 
111
110
  elif self.db_type == "postgres":
@@ -80,6 +80,7 @@ class SQLPyHelper:
80
80
  self.port: Optional[str] = port or os.getenv("DB_PORT")
81
81
  self.oracle_sid: Optional[str] = oracle_sid or os.getenv("ORACLE_SID")
82
82
  self.pool: Any = None
83
+ self._in_transaction: bool = False
83
84
 
84
85
  if not self.db_type or not self.database:
85
86
  raise ValueError("Missing required database configuration.")
@@ -96,6 +97,7 @@ class SQLPyHelper:
96
97
  user=self.user,
97
98
  password=self.password,
98
99
  dbname=self.database,
100
+ port=self.port,
99
101
  )
100
102
  elif self.db_type == "mysql":
101
103
  import mysql.connector
@@ -142,14 +144,14 @@ class SQLPyHelper:
142
144
  self.cursor.execute(query, params)
143
145
  else:
144
146
  self.cursor.execute(query)
145
- self.connection.commit()
147
+ if not self._in_transaction:
148
+ self.connection.commit()
146
149
  except Exception as e:
147
- if "server has gone away" in str(
148
- e
149
- ): # Example check for MySQL lost connection
150
+ if "server has gone away" in str(e):
150
151
  self.reconnect()
151
152
  self.cursor.execute(query, params) # type: ignore[arg-type]
152
- self.connection.commit()
153
+ if not self._in_transaction:
154
+ self.connection.commit()
153
155
  else:
154
156
  raise QueryError(f"Query failed: {e}") from e
155
157
 
@@ -349,6 +351,7 @@ class SQLPyHelper:
349
351
  self.execute_query("BEGIN TRANSACTION")
350
352
  elif self.db_type == "oracle":
351
353
  pass # Oracle starts transactions implicitly on first DML statement
354
+ self._in_transaction = True
352
355
  logger.info("Transaction started on %s database", self.db_type)
353
356
  except Exception as e:
354
357
  raise QueryError(f"Failed to begin transaction: {e}") from e
@@ -357,6 +360,7 @@ class SQLPyHelper:
357
360
  """Commit the current transaction."""
358
361
  try:
359
362
  self.connection.commit()
363
+ self._in_transaction = False
360
364
  logger.info("Transaction committed on %s database", self.db_type)
361
365
  except Exception as e:
362
366
  raise QueryError(f"Failed to commit transaction: {e}") from e
@@ -365,6 +369,7 @@ class SQLPyHelper:
365
369
  """Roll back the current transaction."""
366
370
  try:
367
371
  self.connection.rollback()
372
+ self._in_transaction = False
368
373
  logger.info("Transaction rolled back on %s database", self.db_type)
369
374
  except Exception as e:
370
375
  raise QueryError(f"Failed to rollback transaction: {e}") from e
File without changes
File without changes
File without changes