psycopg-toolkit 0.2.1__tar.gz → 0.2.2__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.
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/PKG-INFO +11 -7
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/README.md +10 -6
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/pyproject.toml +1 -1
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/repositories/base.py +8 -17
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/.gitignore +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/.vscode/settings.json +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/LICENSE +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/__init__.py +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/core/__init__.py +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/core/config.py +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/core/database.py +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/core/factory.py +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/core/transaction.py +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/exceptions.py +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/repositories/__init__.py +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/utils/__init__.py +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/utils/json_handler.py +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/utils/psychopg_helper.py +0 -0
- {psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/utils/type_inspector.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: psycopg-toolkit
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: A Python PostgreSQL database utility with connection pooling
|
|
5
5
|
Project-URL: Homepage, https://github.com/descoped/psycopg-toolkit
|
|
6
6
|
Project-URL: Repository, https://github.com/descoped/psycopg-toolkit
|
|
@@ -206,8 +206,10 @@ class User(BaseModel):
|
|
|
206
206
|
roles: List[str] # PostgreSQL TEXT[] array
|
|
207
207
|
permissions: List[str] # PostgreSQL TEXT[] array
|
|
208
208
|
metadata: Dict[str, Any] # JSONB field
|
|
209
|
-
birthdate: str # ISO date string
|
|
210
|
-
created_at: str # ISO datetime string
|
|
209
|
+
birthdate: str # ISO date string (from DATE)
|
|
210
|
+
created_at: str # ISO datetime string (from TIMESTAMP)
|
|
211
|
+
updated_at: str # ISO datetime string (from TIMESTAMPTZ)
|
|
212
|
+
last_login: str | None # Optional timestamp field
|
|
211
213
|
|
|
212
214
|
class UserRepository(BaseRepository[User, UUID]):
|
|
213
215
|
def __init__(self, conn):
|
|
@@ -218,8 +220,8 @@ class UserRepository(BaseRepository[User, UUID]):
|
|
|
218
220
|
primary_key="id",
|
|
219
221
|
# Preserve PostgreSQL arrays instead of JSONB
|
|
220
222
|
array_fields={"roles", "permissions"},
|
|
221
|
-
# Auto-convert
|
|
222
|
-
date_fields={"birthdate", "created_at"}
|
|
223
|
+
# Auto-convert ALL date/timestamp fields to/from strings
|
|
224
|
+
date_fields={"birthdate", "created_at", "updated_at", "last_login"}
|
|
223
225
|
)
|
|
224
226
|
|
|
225
227
|
# PostgreSQL arrays are preserved, dates are auto-converted
|
|
@@ -229,8 +231,10 @@ user = User(
|
|
|
229
231
|
roles=["admin", "user"], # Stored as TEXT[]
|
|
230
232
|
permissions=["read", "write"], # Stored as TEXT[]
|
|
231
233
|
metadata={"dept": "IT"}, # Stored as JSONB
|
|
232
|
-
birthdate="1990-01-01",
|
|
233
|
-
created_at="2024-01-01T12:00:00" # Converts to/from TIMESTAMP
|
|
234
|
+
birthdate="1990-01-01", # Converts to/from PostgreSQL DATE
|
|
235
|
+
created_at="2024-01-01T12:00:00", # Converts to/from TIMESTAMP
|
|
236
|
+
updated_at="2024-01-01T12:00:00", # Converts to/from TIMESTAMPTZ
|
|
237
|
+
last_login=None # Nullable timestamp field
|
|
234
238
|
)
|
|
235
239
|
```
|
|
236
240
|
|
|
@@ -173,8 +173,10 @@ class User(BaseModel):
|
|
|
173
173
|
roles: List[str] # PostgreSQL TEXT[] array
|
|
174
174
|
permissions: List[str] # PostgreSQL TEXT[] array
|
|
175
175
|
metadata: Dict[str, Any] # JSONB field
|
|
176
|
-
birthdate: str # ISO date string
|
|
177
|
-
created_at: str # ISO datetime string
|
|
176
|
+
birthdate: str # ISO date string (from DATE)
|
|
177
|
+
created_at: str # ISO datetime string (from TIMESTAMP)
|
|
178
|
+
updated_at: str # ISO datetime string (from TIMESTAMPTZ)
|
|
179
|
+
last_login: str | None # Optional timestamp field
|
|
178
180
|
|
|
179
181
|
class UserRepository(BaseRepository[User, UUID]):
|
|
180
182
|
def __init__(self, conn):
|
|
@@ -185,8 +187,8 @@ class UserRepository(BaseRepository[User, UUID]):
|
|
|
185
187
|
primary_key="id",
|
|
186
188
|
# Preserve PostgreSQL arrays instead of JSONB
|
|
187
189
|
array_fields={"roles", "permissions"},
|
|
188
|
-
# Auto-convert
|
|
189
|
-
date_fields={"birthdate", "created_at"}
|
|
190
|
+
# Auto-convert ALL date/timestamp fields to/from strings
|
|
191
|
+
date_fields={"birthdate", "created_at", "updated_at", "last_login"}
|
|
190
192
|
)
|
|
191
193
|
|
|
192
194
|
# PostgreSQL arrays are preserved, dates are auto-converted
|
|
@@ -196,8 +198,10 @@ user = User(
|
|
|
196
198
|
roles=["admin", "user"], # Stored as TEXT[]
|
|
197
199
|
permissions=["read", "write"], # Stored as TEXT[]
|
|
198
200
|
metadata={"dept": "IT"}, # Stored as JSONB
|
|
199
|
-
birthdate="1990-01-01",
|
|
200
|
-
created_at="2024-01-01T12:00:00" # Converts to/from TIMESTAMP
|
|
201
|
+
birthdate="1990-01-01", # Converts to/from PostgreSQL DATE
|
|
202
|
+
created_at="2024-01-01T12:00:00", # Converts to/from TIMESTAMP
|
|
203
|
+
updated_at="2024-01-01T12:00:00", # Converts to/from TIMESTAMPTZ
|
|
204
|
+
last_login=None # Nullable timestamp field
|
|
201
205
|
)
|
|
202
206
|
```
|
|
203
207
|
|
|
@@ -90,8 +90,8 @@ class BaseRepository(Generic[T, K]):
|
|
|
90
90
|
strict_json_processing (bool, optional): Whether to raise exceptions for JSON
|
|
91
91
|
deserialization errors instead of logging warnings. Defaults to False.
|
|
92
92
|
date_fields (Optional[Set[str]], optional): Set of field names that contain
|
|
93
|
-
date values
|
|
94
|
-
Defaults to None.
|
|
93
|
+
date/datetime values needing conversion to ISO strings. Include ALL date,
|
|
94
|
+
timestamp, and timestamptz fields from your model. Defaults to None.
|
|
95
95
|
array_fields (Optional[Set[str]], optional): Set of field names that should be
|
|
96
96
|
treated as PostgreSQL arrays rather than JSONB. Only relevant when
|
|
97
97
|
auto_detect_json=False. Defaults to None.
|
|
@@ -184,10 +184,10 @@ class BaseRepository(Generic[T, K]):
|
|
|
184
184
|
for field_name in self._date_fields:
|
|
185
185
|
if field_name in data and data[field_name] is not None:
|
|
186
186
|
value = data[field_name]
|
|
187
|
-
if isinstance(value, date
|
|
188
|
-
# Convert date to ISO string for storage
|
|
187
|
+
if isinstance(value, date | datetime):
|
|
188
|
+
# Convert date/datetime to ISO string for storage
|
|
189
189
|
processed_data[field_name] = value.isoformat()
|
|
190
|
-
logger.debug(f"Converted date field '{field_name}' to ISO string for {self.table_name}")
|
|
190
|
+
logger.debug(f"Converted date field '{field_name}' from {type(value).__name__} to ISO string for {self.table_name}")
|
|
191
191
|
|
|
192
192
|
# For custom JSON processing, determine which fields need processing
|
|
193
193
|
json_fields = self._json_fields
|
|
@@ -282,25 +282,16 @@ class BaseRepository(Generic[T, K]):
|
|
|
282
282
|
for field_name in self._date_fields:
|
|
283
283
|
if field_name in processed_data and processed_data[field_name] is not None:
|
|
284
284
|
value = processed_data[field_name]
|
|
285
|
-
if isinstance(value, date
|
|
286
|
-
# Convert date to ISO string for Pydantic
|
|
285
|
+
if isinstance(value, date | datetime):
|
|
286
|
+
# Convert date/datetime to ISO string for Pydantic
|
|
287
287
|
processed_data[field_name] = value.isoformat()
|
|
288
|
-
logger.debug(f"Converted date field '{field_name}' from
|
|
288
|
+
logger.debug(f"Converted date field '{field_name}' from {type(value).__name__} to ISO string for {self.table_name}")
|
|
289
289
|
|
|
290
290
|
# If no JSON fields should be processed, return the processed data
|
|
291
291
|
if not json_fields:
|
|
292
292
|
logger.debug(f"No JSON fields configured for {self.table_name}, skipping JSON postprocessing")
|
|
293
293
|
return processed_data
|
|
294
294
|
|
|
295
|
-
# Convert date fields to appropriate format if needed
|
|
296
|
-
for field_name in self._date_fields:
|
|
297
|
-
if field_name in data and data[field_name] is not None:
|
|
298
|
-
value = data[field_name]
|
|
299
|
-
if isinstance(value, date) and not isinstance(value, datetime):
|
|
300
|
-
# Convert date to ISO string for storage
|
|
301
|
-
processed_data[field_name] = value.isoformat()
|
|
302
|
-
logger.debug(f"Converted date field '{field_name}' to ISO string for {self.table_name}")
|
|
303
|
-
|
|
304
295
|
for field_name in self._json_fields:
|
|
305
296
|
if field_name in processed_data and processed_data[field_name] is not None:
|
|
306
297
|
try:
|
|
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
|
{psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/repositories/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{psycopg_toolkit-0.2.1 → psycopg_toolkit-0.2.2}/src/psycopg_toolkit/utils/psychopg_helper.py
RENAMED
|
File without changes
|
|
File without changes
|