python-ppa 0.0.1__py3-none-any.whl → 0.1.4__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.
ppa/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ from ppa import mongo
2
+ from ppa import config
ppa/mongo/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from ppa.mongo.interface import IRepository
2
+ from ppa.mongo.interface import query
3
+ from ppa.mongo.interface import document
@@ -1,16 +1,23 @@
1
1
  import inspect
2
2
  import re
3
3
  from typing import Any, Callable, ClassVar, Generic, TypeVar, cast, get_args, get_origin, get_type_hints, List
4
+ from unittest import result
4
5
 
5
- from pydantic import BaseModel
6
+ from pydantic import BaseModel, ConfigDict
6
7
  from bson import ObjectId, errors
7
8
 
8
- from jpa.config import get_collection, get_framework_logger
9
+ from ppa.config import get_collection, get_framework_logger
9
10
 
10
11
  T = TypeVar("T", bound=BaseModel)
11
12
  F = TypeVar("F", bound=Callable[..., Any])
12
13
  framework_logger = get_framework_logger("repository")
13
14
 
15
+ DEFAULT_DOCUMENT_CONFIG = dict[str, Any] = {
16
+ "populate_by_name": True,
17
+ "arbitrary_types_allowed": True,
18
+ "json_encoders": {ObjectId: str}
19
+ }
20
+
14
21
 
15
22
  class DocumentModel(BaseModel):
16
23
  __collection_name__: ClassVar[str]
@@ -31,6 +38,20 @@ def document(name: str) -> Callable[[type[DocumentModel]], type[DocumentModel]]:
31
38
 
32
39
  def decorator(cls):
33
40
  cls.__collection_name__ = name
41
+ current_cfs = dict(getattr(cls, "model_config", {}) or {})
42
+ current_encoders = dict(current_cfs.get("json_encoders", {}) or {})
43
+ merged_encoders = {
44
+ **DEFAULT_DOCUMENT_CONFIG["json_encoders"],
45
+ **current_encoders
46
+ }
47
+ merged_cfs = {
48
+ **DEFAULT_DOCUMENT_CONFIG["model_config"],
49
+ **current_cfs,
50
+ "json_encoders": merged_encoders,
51
+ }
52
+ cls.model_config = ConfigDict(**merged_cfs)
53
+ if hasattr(cls, "model_rebuild"):
54
+ cls.model_rebuild(force=True)
34
55
  return cls
35
56
 
36
57
  return decorator
@@ -65,7 +86,8 @@ class RepositoryMeta(type):
65
86
  is_convention = re.match(r"(find_by|find_all_by|exists_by|count_by)_(.*)", attr_name)
66
87
 
67
88
  if not is_convention:
68
- raise ValueError("Convention does not exists")
89
+ framework_logger.info("Convention does not exists, relying on user implementation")
90
+ return cls
69
91
 
70
92
  if query_template or is_convention is not None:
71
93
  hints = get_type_hints(attr_value)
@@ -280,17 +302,25 @@ class IRepository(Generic[T], metaclass=RepositoryMeta):
280
302
  cursor = self.collection.find()
281
303
 
282
304
  # 2. Local serialization helper to clean BSON primary keys
283
- def sanitize(doc):
284
- if doc and "_id" in doc:
285
- doc = dict(doc)
286
- doc["_id"] = str(doc["_id"])
287
- return doc
305
+ # def sanitize(doc):
306
+ # if doc and "_id" in doc:
307
+ # doc = dict(doc)
308
+ # doc["_id"] = str(doc["_id"])
309
+ # return doc
288
310
 
289
311
  # 3. Instantiate using self._entity_cls (which holds the real model at runtime)
290
- return [self._entity_cls(**sanitize(data_dict)) for data_dict in cursor]
312
+ return [self._entity_cls(**dict(data_dict)) for data_dict in cursor]
291
313
 
292
314
  def find(self, query_dict: dict) -> T:
293
315
  data = self.collection.find(query_dict)
294
316
  if not data:
295
317
  raise ValueError("No data found")
296
- return dict(data)
318
+ return dict(data)
319
+
320
+ def delete(self, resource_id: str) -> bool:
321
+ query_result = self.collection.delete_one({"_id": ObjectId(resource_id)})
322
+ return query_result.deleted_count > 0
323
+
324
+ def update(self, resource_id: str, data:dict):
325
+ query_result = self.collection.update_one({"_id": ObjectId(resource_id)}, {"$set": data})
326
+ return query_result.modified_count > 0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-ppa
3
- Version: 0.0.1
3
+ Version: 0.1.4
4
4
  Summary: JPA-like ORM for Python
5
5
  Author: Pratyush Kumar
6
6
  License-Expression: MIT
@@ -0,0 +1,9 @@
1
+ ppa/__init__.py,sha256=hPJEX6p9ISqFn9oCk29_HIZYIFVUF_XLEk02dg5fl9c,44
2
+ ppa/config.py,sha256=BpnjdXIYjKe7P8HGKFwZkkTbHf94734dhuT1ki4x0UM,8430
3
+ ppa/mongo/__init__.py,sha256=eOEbRiNLeS8zU6vhyNTIZqOCS6Pg_W_aAfe1JFbq5qk,122
4
+ ppa/mongo/interface.py,sha256=pp8SE35l6sNxBhXjnfaR1jQf6t5ac7VFumSA3cTdW2U,11949
5
+ python_ppa-0.1.4.dist-info/licenses/LICENSE,sha256=J2MOuVHjIUNmdrDLa3O35gQz6E_wAJh9Ke3dod_ZDWc,1071
6
+ python_ppa-0.1.4.dist-info/METADATA,sha256=fjw2JqZRbupY1TFl1mIvQXftePnoq9s3w6-T8t1qQ6w,4903
7
+ python_ppa-0.1.4.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
8
+ python_ppa-0.1.4.dist-info/top_level.txt,sha256=43G6at2pfqB1LsMChCc2_K8WwSSt-LoYBAYN6Sf-krk,4
9
+ python_ppa-0.1.4.dist-info/RECORD,,
@@ -0,0 +1 @@
1
+ ppa
jpa/__init__.py DELETED
@@ -1,2 +0,0 @@
1
- from jpa import mongo
2
- from jpa import config
jpa/mongo/__init__.py DELETED
@@ -1,3 +0,0 @@
1
- from jpa.mongo.interface import IRepository
2
- from jpa.mongo.interface import query
3
- from jpa.mongo.interface import document
@@ -1,9 +0,0 @@
1
- jpa/__init__.py,sha256=xuglU4WFGcuOUnNS3cgPA7hY6MpNm7RhRMClDsoJn7w,44
2
- jpa/config.py,sha256=BpnjdXIYjKe7P8HGKFwZkkTbHf94734dhuT1ki4x0UM,8430
3
- jpa/mongo/__init__.py,sha256=miJ75M7NhhzFGh1mPhEauLD5-mqMs2JR0s1uz_e1zwk,122
4
- jpa/mongo/interface.py,sha256=5BYJW-NdMqdNyKA6CrRVEjZCG-LmnqVDsN59tkH2j0s,10743
5
- python_ppa-0.0.1.dist-info/licenses/LICENSE,sha256=J2MOuVHjIUNmdrDLa3O35gQz6E_wAJh9Ke3dod_ZDWc,1071
6
- python_ppa-0.0.1.dist-info/METADATA,sha256=fT8Z7SIu1Yv-Y162znZLhLaZhLV-fq_zIKZbDqbTITw,4903
7
- python_ppa-0.0.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
8
- python_ppa-0.0.1.dist-info/top_level.txt,sha256=Ff25NuPyZ4QIlYXMgPtFLgeYqSKfD9Ynjmjev_Bf1nw,4
9
- python_ppa-0.0.1.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- jpa
{jpa → ppa}/config.py RENAMED
File without changes