devsetgo-lib 0.13.2__tar.gz → 0.14.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.
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/PKG-INFO +16 -13
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/README.md +15 -12
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/__init__.py +1 -1
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/async_database_functions/__import_sqlalchemy.py +48 -19
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/async_database_functions/async_database.py +5 -5
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/async_database_functions/base_schema.py +25 -21
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/async_database_functions/database_config.py +25 -17
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/async_database_functions/database_operations.py +100 -100
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/common_functions/calendar_functions.py +33 -31
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/common_functions/email_validation.py +67 -30
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/common_functions/file_functions.py +115 -111
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/common_functions/folder_functions.py +8 -8
- devsetgo_lib-0.14.0/dsg_lib/common_functions/logging_config.py +379 -0
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/common_functions/patterns.py +21 -19
- devsetgo_lib-0.14.0/dsg_lib/fastapi_functions/_all_codes.py +356 -0
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/fastapi_functions/http_codes.py +5 -3
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/fastapi_functions/system_health_endpoints.py +36 -30
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/pyproject.toml +1 -1
- devsetgo_lib-0.13.2/dsg_lib/common_functions/logging_config.py +0 -270
- devsetgo_lib-0.13.2/dsg_lib/fastapi_functions/_all_codes.py +0 -356
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/.gitignore +0 -0
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/LICENSE +0 -0
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/async_database_functions/__init__.py +0 -0
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/common_functions/__init__.py +0 -0
- {devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/fastapi_functions/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: devsetgo_lib
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.14.0
|
|
4
4
|
Summary: DevSetGo Library is a Python library offering reusable functions for efficient coding. It includes file operations, calendar utilities, pattern matching, advanced logging with loguru, FastAPI endpoints, async database handling, and email validation. Designed for ease of use and versatility, it's a valuable tool for Python developers.
|
|
5
5
|
Project-URL: Homepage, https://github.com/devsetgo/devsetgo_lib
|
|
6
6
|
Project-URL: Documentation, https://devsetgo.github.io/devsetgo_lib/
|
|
@@ -103,27 +103,30 @@ SonarCloud:
|
|
|
103
103
|
|
|
104
104
|
## Key Features
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
- **
|
|
108
|
-
|
|
106
|
+
### **Common Functions**:
|
|
107
|
+
- **File Operations**:
|
|
108
|
+
- **CSV, JSON, and Text File Functions**: Create, read, write, and manipulate various file types with ease.
|
|
109
|
+
- **Folder Functions**: Create and remove directories, list directory contents, and manage file system operations efficiently.
|
|
109
110
|
|
|
110
|
-
- **Logging**:
|
|
111
|
-
|
|
111
|
+
- **Logging**:
|
|
112
|
+
Comprehensive logging setup using the [Loguru Library]('https://loguru.readthedocs.io/en/stable/overview.html'). Provides extensive customization options for log configuration, including log rotation, retention, and formatting. Includes improvements for multiprocessing environments to ensure log messages are handled correctly across multiple processes.
|
|
112
113
|
|
|
113
|
-
- **Calendar Functions**:
|
|
114
|
-
|
|
114
|
+
- **Calendar Functions**:
|
|
115
|
+
Convert between month names and numbers seamlessly.
|
|
115
116
|
|
|
116
|
-
- **Pattern Matching**:
|
|
117
|
-
|
|
117
|
+
- **Pattern Matching**:
|
|
118
|
+
Powerful tools for searching patterns in text using regular expressions.
|
|
118
119
|
|
|
119
|
-
|
|
120
|
+
|
|
121
|
+
### **FastAPI Endpoints**:
|
|
120
122
|
- Pre-built endpoints for system health checks, status, and uptime monitoring.
|
|
121
123
|
- Functions to generate HTTP response codes easily.
|
|
122
124
|
|
|
123
|
-
|
|
125
|
+
### **Async Database**:
|
|
124
126
|
- Configuration and management of asynchronous database sessions.
|
|
125
127
|
- CRUD operations with async support.
|
|
126
128
|
|
|
129
|
+
---
|
|
127
130
|
## Installation
|
|
128
131
|
|
|
129
132
|
To install `devsetgo_lib`, use pip:
|
|
@@ -152,7 +155,7 @@ pip install devsetgo-lib[all]
|
|
|
152
155
|
Here's a quick example to demonstrate how you can use some of the key features of `devsetgo_lib`:
|
|
153
156
|
|
|
154
157
|
```python
|
|
155
|
-
from devsetgo_lib import file_functions, logging_config, patterns, calendar_functions
|
|
158
|
+
from devsetgo_lib.common_functions import file_functions, logging_config, patterns, calendar_functions
|
|
156
159
|
|
|
157
160
|
# File Operations
|
|
158
161
|
file_functions.create_sample_files("example", 100)
|
|
@@ -31,27 +31,30 @@ SonarCloud:
|
|
|
31
31
|
|
|
32
32
|
## Key Features
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
- **
|
|
36
|
-
|
|
34
|
+
### **Common Functions**:
|
|
35
|
+
- **File Operations**:
|
|
36
|
+
- **CSV, JSON, and Text File Functions**: Create, read, write, and manipulate various file types with ease.
|
|
37
|
+
- **Folder Functions**: Create and remove directories, list directory contents, and manage file system operations efficiently.
|
|
37
38
|
|
|
38
|
-
- **Logging**:
|
|
39
|
-
|
|
39
|
+
- **Logging**:
|
|
40
|
+
Comprehensive logging setup using the [Loguru Library]('https://loguru.readthedocs.io/en/stable/overview.html'). Provides extensive customization options for log configuration, including log rotation, retention, and formatting. Includes improvements for multiprocessing environments to ensure log messages are handled correctly across multiple processes.
|
|
40
41
|
|
|
41
|
-
- **Calendar Functions**:
|
|
42
|
-
|
|
42
|
+
- **Calendar Functions**:
|
|
43
|
+
Convert between month names and numbers seamlessly.
|
|
43
44
|
|
|
44
|
-
- **Pattern Matching**:
|
|
45
|
-
|
|
45
|
+
- **Pattern Matching**:
|
|
46
|
+
Powerful tools for searching patterns in text using regular expressions.
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
|
|
49
|
+
### **FastAPI Endpoints**:
|
|
48
50
|
- Pre-built endpoints for system health checks, status, and uptime monitoring.
|
|
49
51
|
- Functions to generate HTTP response codes easily.
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
### **Async Database**:
|
|
52
54
|
- Configuration and management of asynchronous database sessions.
|
|
53
55
|
- CRUD operations with async support.
|
|
54
56
|
|
|
57
|
+
---
|
|
55
58
|
## Installation
|
|
56
59
|
|
|
57
60
|
To install `devsetgo_lib`, use pip:
|
|
@@ -80,7 +83,7 @@ pip install devsetgo-lib[all]
|
|
|
80
83
|
Here's a quick example to demonstrate how you can use some of the key features of `devsetgo_lib`:
|
|
81
84
|
|
|
82
85
|
```python
|
|
83
|
-
from devsetgo_lib import file_functions, logging_config, patterns, calendar_functions
|
|
86
|
+
from devsetgo_lib.common_functions import file_functions, logging_config, patterns, calendar_functions
|
|
84
87
|
|
|
85
88
|
# File Operations
|
|
86
89
|
file_functions.create_sample_files("example", 100)
|
{devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/async_database_functions/__import_sqlalchemy.py
RENAMED
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
This module provides functionality to import and validate SQLAlchemy components, ensuring compatibility with the required version.
|
|
4
|
+
|
|
5
|
+
The `import_sqlalchemy` function is the primary function in this module. It imports various components from SQLAlchemy, checks the version of SQLAlchemy, and raises an ImportError if the version is below the minimum required version.
|
|
6
|
+
|
|
7
|
+
Usage example:
|
|
8
|
+
```python
|
|
9
|
+
from import_sqlalchemy import import_sqlalchemy
|
|
10
|
+
|
|
11
|
+
sqlalchemy_components = import_sqlalchemy()
|
|
12
|
+
sqlalchemy, MetaData, create_engine, text, Column, DateTime, String, IntegrityError, SQLAlchemyError, AsyncSession = sqlalchemy_components
|
|
13
|
+
|
|
14
|
+
# Example usage of imported components
|
|
15
|
+
engine = create_engine('sqlite:///example.db')
|
|
16
|
+
metadata = MetaData()
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Author(s):
|
|
20
|
+
Mike Ryan
|
|
21
|
+
|
|
22
|
+
Date Created:
|
|
23
|
+
2024/05/16
|
|
24
|
+
Date Updated:
|
|
25
|
+
2024/07/26
|
|
26
|
+
"""
|
|
2
27
|
from typing import Tuple
|
|
3
28
|
|
|
4
29
|
from loguru import logger
|
|
@@ -15,7 +40,7 @@ def import_sqlalchemy() -> Tuple:
|
|
|
15
40
|
and raises an ImportError if the version is less than the minimum required version.
|
|
16
41
|
|
|
17
42
|
Returns:
|
|
18
|
-
|
|
43
|
+
Tuple: A tuple containing the following SQLAlchemy components:
|
|
19
44
|
- sqlalchemy: The SQLAlchemy module.
|
|
20
45
|
- MetaData: The MetaData class from SQLAlchemy.
|
|
21
46
|
- create_engine: The create_engine function from SQLAlchemy.
|
|
@@ -26,23 +51,25 @@ def import_sqlalchemy() -> Tuple:
|
|
|
26
51
|
- IntegrityError: The IntegrityError exception from SQLAlchemy.
|
|
27
52
|
- SQLAlchemyError: The SQLAlchemyError exception from SQLAlchemy.
|
|
28
53
|
- AsyncSession: The AsyncSession class from SQLAlchemy.
|
|
29
|
-
- create_async_engine: The create_async_engine function from SQLAlchemy.
|
|
30
|
-
- select: The select function from SQLAlchemy.
|
|
31
|
-
- declarative_base: The declarative_base function from SQLAlchemy.
|
|
32
|
-
- sessionmaker: The sessionmaker function from SQLAlchemy.
|
|
33
|
-
- func: The func object from SQLAlchemy.
|
|
34
|
-
- NoResultFound: The NoResultFound exception from SQLAlchemy.
|
|
35
54
|
|
|
36
55
|
Raises:
|
|
37
|
-
ImportError: If the
|
|
56
|
+
ImportError: If SQLAlchemy is not installed or the version is below the minimum required version.
|
|
57
|
+
|
|
58
|
+
Example:
|
|
59
|
+
```python
|
|
60
|
+
from import_sqlalchemy import import_sqlalchemy
|
|
61
|
+
|
|
62
|
+
sqlalchemy_components = import_sqlalchemy()
|
|
63
|
+
sqlalchemy, MetaData, create_engine, text, Column, DateTime, String, IntegrityError, SQLAlchemyError, AsyncSession = sqlalchemy_components
|
|
38
64
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
65
|
+
# Example usage of imported components
|
|
66
|
+
engine = create_engine('sqlite:///example.db')
|
|
67
|
+
metadata = MetaData()
|
|
68
|
+
```
|
|
42
69
|
"""
|
|
43
|
-
min_version =
|
|
70
|
+
min_version = "2.0.0" # Minimum required version of SQLAlchemy
|
|
44
71
|
|
|
45
|
-
logger.info(
|
|
72
|
+
logger.info("Attempting to import SQLAlchemy...")
|
|
46
73
|
|
|
47
74
|
try:
|
|
48
75
|
# Import SQLAlchemy and its components
|
|
@@ -55,11 +82,11 @@ def import_sqlalchemy() -> Tuple:
|
|
|
55
82
|
from sqlalchemy.orm.exc import NoResultFound
|
|
56
83
|
from sqlalchemy.sql import func
|
|
57
84
|
|
|
58
|
-
logger.info(
|
|
85
|
+
logger.info("Successfully imported SQLAlchemy.")
|
|
59
86
|
|
|
60
87
|
except ImportError: # pragma: no cover
|
|
61
88
|
# Handle the case where SQLAlchemy is not installed
|
|
62
|
-
logger.error(
|
|
89
|
+
logger.error("Failed to import SQLAlchemy.")
|
|
63
90
|
create_engine = text = sqlalchemy = None # pragma: no cover
|
|
64
91
|
|
|
65
92
|
# Check SQLAlchemy version
|
|
@@ -68,13 +95,13 @@ def import_sqlalchemy() -> Tuple:
|
|
|
68
95
|
) < packaging_version.parse(min_version):
|
|
69
96
|
# If the installed version is less than the minimum required version, raise an error
|
|
70
97
|
logger.error(
|
|
71
|
-
f
|
|
98
|
+
f"SQLAlchemy version >= {min_version} required, run `pip install --upgrade sqlalchemy`"
|
|
72
99
|
)
|
|
73
100
|
raise ImportError(
|
|
74
|
-
f
|
|
101
|
+
f"SQLAlchemy version >= {min_version} required, run `pip install --upgrade sqlalchemy`"
|
|
75
102
|
) # pragma: no cover
|
|
76
103
|
|
|
77
|
-
logger.info(
|
|
104
|
+
logger.info("Returning SQLAlchemy components.")
|
|
78
105
|
|
|
79
106
|
# Return the imported SQLAlchemy components
|
|
80
107
|
return (
|
|
@@ -118,4 +145,6 @@ def import_sqlalchemy() -> Tuple:
|
|
|
118
145
|
String, # The String class from SQLAlchemy
|
|
119
146
|
func, # The func object from SQLAlchemy
|
|
120
147
|
NoResultFound, # The NoResultFound exception from SQLAlchemy
|
|
121
|
-
) =
|
|
148
|
+
) = (
|
|
149
|
+
import_sqlalchemy()
|
|
150
|
+
) # Call the function that imports SQLAlchemy and checks its version
|
{devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/async_database_functions/async_database.py
RENAMED
|
@@ -85,7 +85,7 @@ class AsyncDatabase:
|
|
|
85
85
|
"""
|
|
86
86
|
self.db_config = db_config
|
|
87
87
|
self.Base = BASE
|
|
88
|
-
logger.debug(
|
|
88
|
+
logger.debug("AsyncDatabase initialized")
|
|
89
89
|
|
|
90
90
|
def get_db_session(self):
|
|
91
91
|
"""This method returns a context manager that provides a new database
|
|
@@ -96,7 +96,7 @@ class AsyncDatabase:
|
|
|
96
96
|
Returns: contextlib._GeneratorContextManager: A context manager that
|
|
97
97
|
provides a new database session.
|
|
98
98
|
"""
|
|
99
|
-
logger.debug(
|
|
99
|
+
logger.debug("Getting database session")
|
|
100
100
|
return self.db_config.get_db_session()
|
|
101
101
|
|
|
102
102
|
async def create_tables(self):
|
|
@@ -106,7 +106,7 @@ class AsyncDatabase:
|
|
|
106
106
|
|
|
107
107
|
Returns: None
|
|
108
108
|
"""
|
|
109
|
-
logger.debug(
|
|
109
|
+
logger.debug("Creating tables")
|
|
110
110
|
try:
|
|
111
111
|
# Bind the engine to the metadata of the base class
|
|
112
112
|
self.Base.metadata.bind = self.db_config.engine
|
|
@@ -115,8 +115,8 @@ class AsyncDatabase:
|
|
|
115
115
|
async with self.db_config.engine.begin() as conn:
|
|
116
116
|
# Run a function in a synchronous manner
|
|
117
117
|
await conn.run_sync(self.Base.metadata.create_all)
|
|
118
|
-
logger.info(
|
|
118
|
+
logger.info("Tables created successfully")
|
|
119
119
|
except Exception as ex: # pragma: no cover
|
|
120
120
|
# Log the error and raise it
|
|
121
|
-
logger.error(f
|
|
121
|
+
logger.error(f"Error creating tables: {ex}") # pragma: no cover
|
|
122
122
|
raise # pragma: no cover
|
|
@@ -56,14 +56,18 @@ from .__import_sqlalchemy import import_sqlalchemy
|
|
|
56
56
|
String, # The String class from SQLAlchemy
|
|
57
57
|
func, # The func object from SQLAlchemy
|
|
58
58
|
NoResultFound, # The NoResultFound exception from SQLAlchemy
|
|
59
|
-
) =
|
|
59
|
+
) = (
|
|
60
|
+
import_sqlalchemy()
|
|
61
|
+
) # Call the function that imports SQLAlchemy and checks its version
|
|
60
62
|
|
|
61
63
|
|
|
62
64
|
# comments
|
|
63
|
-
uuid_comment =
|
|
64
|
-
date_created_comment =
|
|
65
|
+
uuid_comment = "Unique identifier for each record, a string representation of a UUID"
|
|
66
|
+
date_created_comment = (
|
|
67
|
+
"Date and time when a row was inserted, defaults to current UTC time"
|
|
68
|
+
)
|
|
65
69
|
date_updated_comment = (
|
|
66
|
-
|
|
70
|
+
"Date and time when a row was last updated, defaults to current UTC time on update"
|
|
67
71
|
)
|
|
68
72
|
|
|
69
73
|
|
|
@@ -228,7 +232,7 @@ class SchemaBaseMySQL:
|
|
|
228
232
|
date_created = Column(
|
|
229
233
|
DateTime,
|
|
230
234
|
index=True,
|
|
231
|
-
server_default=text(
|
|
235
|
+
server_default=text("UTC_TIMESTAMP()"),
|
|
232
236
|
comment=date_created_comment,
|
|
233
237
|
)
|
|
234
238
|
|
|
@@ -237,8 +241,8 @@ class SchemaBaseMySQL:
|
|
|
237
241
|
date_updated = Column(
|
|
238
242
|
DateTime,
|
|
239
243
|
index=True,
|
|
240
|
-
server_default=text(
|
|
241
|
-
onupdate=text(
|
|
244
|
+
server_default=text("UTC_TIMESTAMP()"),
|
|
245
|
+
onupdate=text("UTC_TIMESTAMP()"),
|
|
242
246
|
comment=date_updated_comment,
|
|
243
247
|
)
|
|
244
248
|
|
|
@@ -287,7 +291,7 @@ class SchemaBaseOracle:
|
|
|
287
291
|
date_created = Column(
|
|
288
292
|
DateTime,
|
|
289
293
|
index=True,
|
|
290
|
-
server_default=text(
|
|
294
|
+
server_default=text("SYS_EXTRACT_UTC(SYSTIMESTAMP)"),
|
|
291
295
|
comment=date_created_comment,
|
|
292
296
|
)
|
|
293
297
|
|
|
@@ -296,8 +300,8 @@ class SchemaBaseOracle:
|
|
|
296
300
|
date_updated = Column(
|
|
297
301
|
DateTime,
|
|
298
302
|
index=True,
|
|
299
|
-
server_default=text(
|
|
300
|
-
onupdate=text(
|
|
303
|
+
server_default=text("SYS_EXTRACT_UTC(SYSTIMESTAMP)"),
|
|
304
|
+
onupdate=text("SYS_EXTRACT_UTC(SYSTIMESTAMP)"),
|
|
301
305
|
comment=date_updated_comment,
|
|
302
306
|
)
|
|
303
307
|
|
|
@@ -346,7 +350,7 @@ class SchemaBaseMSSQL:
|
|
|
346
350
|
date_created = Column(
|
|
347
351
|
DateTime,
|
|
348
352
|
index=True,
|
|
349
|
-
server_default=text(
|
|
353
|
+
server_default=text("GETUTCDATE()"),
|
|
350
354
|
comment=date_created_comment,
|
|
351
355
|
)
|
|
352
356
|
|
|
@@ -355,8 +359,8 @@ class SchemaBaseMSSQL:
|
|
|
355
359
|
date_updated = Column(
|
|
356
360
|
DateTime,
|
|
357
361
|
index=True,
|
|
358
|
-
server_default=text(
|
|
359
|
-
onupdate=text(
|
|
362
|
+
server_default=text("GETUTCDATE()"),
|
|
363
|
+
onupdate=text("GETUTCDATE()"),
|
|
360
364
|
comment=date_updated_comment,
|
|
361
365
|
)
|
|
362
366
|
|
|
@@ -405,8 +409,8 @@ class SchemaBaseFirebird:
|
|
|
405
409
|
date_created = Column(
|
|
406
410
|
DateTime,
|
|
407
411
|
index=True,
|
|
408
|
-
server_default=text(
|
|
409
|
-
comment=
|
|
412
|
+
server_default=text("CURRENT_TIMESTAMP"),
|
|
413
|
+
comment="Date and time when a row was inserted, defaults to current time",
|
|
410
414
|
)
|
|
411
415
|
|
|
412
416
|
# The date and time when a particular row was last updated. It defaults to
|
|
@@ -414,9 +418,9 @@ class SchemaBaseFirebird:
|
|
|
414
418
|
date_updated = Column(
|
|
415
419
|
DateTime,
|
|
416
420
|
index=True,
|
|
417
|
-
server_default=text(
|
|
418
|
-
onupdate=text(
|
|
419
|
-
comment=
|
|
421
|
+
server_default=text("CURRENT_TIMESTAMP"),
|
|
422
|
+
onupdate=text("CURRENT_TIMESTAMP"),
|
|
423
|
+
comment="Date and time when a row was last updated, defaults to current time on update",
|
|
420
424
|
)
|
|
421
425
|
|
|
422
426
|
|
|
@@ -464,7 +468,7 @@ class SchemaBaseSybase:
|
|
|
464
468
|
date_created = Column(
|
|
465
469
|
DateTime,
|
|
466
470
|
index=True,
|
|
467
|
-
server_default=text(
|
|
471
|
+
server_default=text("GETUTCDATE()"),
|
|
468
472
|
comment=date_created_comment,
|
|
469
473
|
)
|
|
470
474
|
|
|
@@ -473,8 +477,8 @@ class SchemaBaseSybase:
|
|
|
473
477
|
date_updated = Column(
|
|
474
478
|
DateTime,
|
|
475
479
|
index=True,
|
|
476
|
-
server_default=text(
|
|
477
|
-
onupdate=text(
|
|
480
|
+
server_default=text("GETUTCDATE()"),
|
|
481
|
+
onupdate=text("GETUTCDATE()"),
|
|
478
482
|
comment=date_updated_comment,
|
|
479
483
|
)
|
|
480
484
|
|
{devsetgo_lib-0.13.2 → devsetgo_lib-0.14.0}/dsg_lib/async_database_functions/database_config.py
RENAMED
|
@@ -67,7 +67,9 @@ from .__import_sqlalchemy import import_sqlalchemy
|
|
|
67
67
|
String, # The String class from SQLAlchemy
|
|
68
68
|
func, # The func object from SQLAlchemy
|
|
69
69
|
NoResultFound, # The NoResultFound exception from SQLAlchemy
|
|
70
|
-
) =
|
|
70
|
+
) = (
|
|
71
|
+
import_sqlalchemy()
|
|
72
|
+
) # Call the function that imports SQLAlchemy and checks its version
|
|
71
73
|
|
|
72
74
|
|
|
73
75
|
# Now you can use declarative_base at the module level
|
|
@@ -118,15 +120,15 @@ class DBConfig:
|
|
|
118
120
|
"""
|
|
119
121
|
|
|
120
122
|
SUPPORTED_PARAMETERS = {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
"sqlite": {"echo", "future", "pool_recycle"},
|
|
124
|
+
"postgresql": {
|
|
125
|
+
"echo",
|
|
126
|
+
"future",
|
|
127
|
+
"pool_pre_ping",
|
|
128
|
+
"pool_size",
|
|
129
|
+
"max_overflow",
|
|
130
|
+
"pool_recycle",
|
|
131
|
+
"pool_timeout",
|
|
130
132
|
},
|
|
131
133
|
# Add other engines here...
|
|
132
134
|
}
|
|
@@ -175,11 +177,15 @@ class DBConfig:
|
|
|
175
177
|
```
|
|
176
178
|
"""
|
|
177
179
|
self.config = config
|
|
178
|
-
engine_type = self.config[
|
|
180
|
+
engine_type = self.config["database_uri"].split("+")[0]
|
|
179
181
|
supported_parameters = self.SUPPORTED_PARAMETERS.get(engine_type, set())
|
|
180
|
-
unsupported_parameters =
|
|
182
|
+
unsupported_parameters = (
|
|
183
|
+
set(config.keys()) - supported_parameters - {"database_uri"}
|
|
184
|
+
)
|
|
181
185
|
if unsupported_parameters:
|
|
182
|
-
error_message =
|
|
186
|
+
error_message = (
|
|
187
|
+
f"Unsupported parameters for {engine_type}: {unsupported_parameters}"
|
|
188
|
+
)
|
|
183
189
|
logger.error(error_message)
|
|
184
190
|
raise Exception(error_message)
|
|
185
191
|
|
|
@@ -188,7 +194,9 @@ class DBConfig:
|
|
|
188
194
|
for param in supported_parameters
|
|
189
195
|
if self.config.get(param) is not None
|
|
190
196
|
}
|
|
191
|
-
self.engine = create_async_engine(
|
|
197
|
+
self.engine = create_async_engine(
|
|
198
|
+
self.config["database_uri"], **engine_parameters
|
|
199
|
+
)
|
|
192
200
|
self.metadata = MetaData()
|
|
193
201
|
|
|
194
202
|
@asynccontextmanager
|
|
@@ -229,7 +237,7 @@ class DBConfig:
|
|
|
229
237
|
# Perform your database operations here pass
|
|
230
238
|
```
|
|
231
239
|
"""
|
|
232
|
-
logger.debug(
|
|
240
|
+
logger.debug("Creating new database session")
|
|
233
241
|
try:
|
|
234
242
|
# Create a new database session
|
|
235
243
|
async with sessionmaker(
|
|
@@ -239,8 +247,8 @@ class DBConfig:
|
|
|
239
247
|
yield session
|
|
240
248
|
except SQLAlchemyError as e: # pragma: no cover
|
|
241
249
|
# Log the error and raise it
|
|
242
|
-
logger.error(f
|
|
250
|
+
logger.error(f"Database error occurred: {str(e)}") # pragma: no cover
|
|
243
251
|
raise # pragma: no cover
|
|
244
252
|
finally: # pragma: no cover
|
|
245
253
|
# Log the end of the database session
|
|
246
|
-
logger.debug(
|
|
254
|
+
logger.debug("Database session ended") # pragma: no cover
|