mongo-entity-orm 0.1.2__tar.gz → 0.1.4__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.
- {mongo_entity_orm-0.1.2 → mongo_entity_orm-0.1.4}/PKG-INFO +1 -1
- {mongo_entity_orm-0.1.2 → mongo_entity_orm-0.1.4}/pyproject.toml +1 -1
- {mongo_entity_orm-0.1.2 → mongo_entity_orm-0.1.4}/src/mongo_orm/core.py +17 -13
- {mongo_entity_orm-0.1.2 → mongo_entity_orm-0.1.4}/src/mongo_orm/utils.py +8 -8
- {mongo_entity_orm-0.1.2 → mongo_entity_orm-0.1.4}/LICENSE +0 -0
- {mongo_entity_orm-0.1.2 → mongo_entity_orm-0.1.4}/README.md +0 -0
- {mongo_entity_orm-0.1.2 → mongo_entity_orm-0.1.4}/src/mongo_orm/__init__.py +0 -0
|
@@ -309,7 +309,7 @@ class BaseEntity(BaseModel):
|
|
|
309
309
|
)
|
|
310
310
|
|
|
311
311
|
@classmethod
|
|
312
|
-
def delete_by_id(cls, id, tenant_id: str):
|
|
312
|
+
def delete_by_id(cls, id, tenant_id: str = "*") -> bool:
|
|
313
313
|
|
|
314
314
|
filter = {"_id": id}
|
|
315
315
|
if tenant_id != "*":
|
|
@@ -321,7 +321,7 @@ class BaseEntity(BaseModel):
|
|
|
321
321
|
def get(
|
|
322
322
|
cls: Type[T],
|
|
323
323
|
id: str,
|
|
324
|
-
tenant_id: str,
|
|
324
|
+
tenant_id: str = "*",
|
|
325
325
|
namespace: str = None,
|
|
326
326
|
raise_not_found: bool = False,
|
|
327
327
|
) -> T | None:
|
|
@@ -342,7 +342,7 @@ class BaseEntity(BaseModel):
|
|
|
342
342
|
async def aget(
|
|
343
343
|
cls: Type[T],
|
|
344
344
|
id: str,
|
|
345
|
-
tenant_id: str,
|
|
345
|
+
tenant_id: str = "*",
|
|
346
346
|
namespace: str = None,
|
|
347
347
|
raise_not_found: bool = False,
|
|
348
348
|
) -> T | None:
|
|
@@ -378,7 +378,7 @@ class BaseEntity(BaseModel):
|
|
|
378
378
|
return entity
|
|
379
379
|
|
|
380
380
|
@classmethod
|
|
381
|
-
def count(cls, tenant_id: str, filter: dict = None, limit=None) -> int:
|
|
381
|
+
def count(cls, tenant_id: str = "*", filter: dict = None, limit=None) -> int:
|
|
382
382
|
|
|
383
383
|
if not filter:
|
|
384
384
|
_filter = {}
|
|
@@ -394,7 +394,7 @@ class BaseEntity(BaseModel):
|
|
|
394
394
|
return cls.collection.count_documents(_filter, **extra)
|
|
395
395
|
|
|
396
396
|
@classmethod
|
|
397
|
-
async def acount(cls, tenant_id: str, filter: dict = None, limit=None) -> int:
|
|
397
|
+
async def acount(cls, tenant_id: str = "*", filter: dict = None, limit=None) -> int:
|
|
398
398
|
|
|
399
399
|
if not filter:
|
|
400
400
|
_filter = {}
|
|
@@ -412,7 +412,7 @@ class BaseEntity(BaseModel):
|
|
|
412
412
|
@classmethod
|
|
413
413
|
async def afind(
|
|
414
414
|
cls: Type[T],
|
|
415
|
-
tenant_id: str,
|
|
415
|
+
tenant_id: str = "*",
|
|
416
416
|
namespace: str = None,
|
|
417
417
|
skip: int = 0,
|
|
418
418
|
limit: int = 100,
|
|
@@ -422,8 +422,10 @@ class BaseEntity(BaseModel):
|
|
|
422
422
|
) -> List[T]:
|
|
423
423
|
if not filter:
|
|
424
424
|
filter = {}
|
|
425
|
+
else:
|
|
426
|
+
filter = {**filter}
|
|
425
427
|
if tenant_id != "*":
|
|
426
|
-
filter.update({"tenant_id": tenant_id
|
|
428
|
+
filter.update({"tenant_id": tenant_id})
|
|
427
429
|
|
|
428
430
|
filter.update(additional_filters)
|
|
429
431
|
if "id" in filter:
|
|
@@ -454,7 +456,7 @@ class BaseEntity(BaseModel):
|
|
|
454
456
|
@classmethod
|
|
455
457
|
def scroll_pages(
|
|
456
458
|
cls: Type[T],
|
|
457
|
-
tenant_id: str,
|
|
459
|
+
tenant_id: str = "*",
|
|
458
460
|
filter: dict = None,
|
|
459
461
|
order_by: str = None,
|
|
460
462
|
page_size: int = 100,
|
|
@@ -476,7 +478,7 @@ class BaseEntity(BaseModel):
|
|
|
476
478
|
@classmethod
|
|
477
479
|
async def ascroll_pages(
|
|
478
480
|
cls: Type[T],
|
|
479
|
-
tenant_id: str,
|
|
481
|
+
tenant_id: str = "*",
|
|
480
482
|
filter: dict = None,
|
|
481
483
|
order_by: str = None,
|
|
482
484
|
page_size: int = 100,
|
|
@@ -498,7 +500,7 @@ class BaseEntity(BaseModel):
|
|
|
498
500
|
@classmethod
|
|
499
501
|
def find(
|
|
500
502
|
cls: Type[T],
|
|
501
|
-
tenant_id: str,
|
|
503
|
+
tenant_id: str = "*",
|
|
502
504
|
namespace: str = None,
|
|
503
505
|
skip: int = 0,
|
|
504
506
|
limit: int | None = 100,
|
|
@@ -511,7 +513,7 @@ class BaseEntity(BaseModel):
|
|
|
511
513
|
else:
|
|
512
514
|
filter = {**filter}
|
|
513
515
|
if tenant_id != "*":
|
|
514
|
-
filter.update({"tenant_id": tenant_id
|
|
516
|
+
filter.update({"tenant_id": tenant_id})
|
|
515
517
|
|
|
516
518
|
filter.update(additional_filters)
|
|
517
519
|
if "id" in filter:
|
|
@@ -544,13 +546,15 @@ class BaseEntity(BaseModel):
|
|
|
544
546
|
return res
|
|
545
547
|
|
|
546
548
|
@classmethod
|
|
547
|
-
def find_first(cls, tenant_id, filter=None, order_by=None, **kwargs):
|
|
549
|
+
def find_first(cls, tenant_id: str = "*", filter=None, order_by=None, **kwargs):
|
|
548
550
|
kwargs.pop("limit", None)
|
|
549
551
|
items = cls.find(tenant_id, filter=filter, order_by=order_by, limit=1, **kwargs)
|
|
550
552
|
return items[0] if items else None
|
|
551
553
|
|
|
552
554
|
@classmethod
|
|
553
|
-
async def afind_first(
|
|
555
|
+
async def afind_first(
|
|
556
|
+
cls, tenant_id: str = "*", filter=None, order_by=None, **kwargs
|
|
557
|
+
):
|
|
554
558
|
items = await cls.afind(
|
|
555
559
|
tenant_id, filter=filter, order_by=order_by, limit=1, **kwargs
|
|
556
560
|
)
|
|
@@ -17,11 +17,11 @@ def _get_index_hash(collection_name: str, spec: "IndexSpec") -> str:
|
|
|
17
17
|
# Normalize keys to a stable tuple representation
|
|
18
18
|
if isinstance(keys, dict):
|
|
19
19
|
# Keep order as provided in dict
|
|
20
|
-
norm_keys = tuple((str(k),
|
|
20
|
+
norm_keys = tuple((str(k), str(v)) for k, v in keys.items())
|
|
21
21
|
elif isinstance(keys, list):
|
|
22
|
-
norm_keys = tuple((str(k),
|
|
22
|
+
norm_keys = tuple((str(k), str(v)) for k, v in keys)
|
|
23
23
|
else:
|
|
24
|
-
norm_keys = ((str(keys), 1.0),)
|
|
24
|
+
norm_keys = ((str(keys), "1.0"),)
|
|
25
25
|
|
|
26
26
|
# Create a stable representation of the spec including important options
|
|
27
27
|
relevant_parts = {
|
|
@@ -48,10 +48,10 @@ def index_exists(collection: Collection, spec: "IndexSpec") -> bool:
|
|
|
48
48
|
elif isinstance(keys, list):
|
|
49
49
|
target_key = keys
|
|
50
50
|
else:
|
|
51
|
-
target_key = [(keys, 1)]
|
|
51
|
+
target_key = [(keys, "1.0")]
|
|
52
52
|
|
|
53
|
-
# Normalize values to
|
|
54
|
-
target_key = [(str(k),
|
|
53
|
+
# Normalize values to strings for comparison
|
|
54
|
+
target_key = [(str(k), str(v)) for k, v in target_key]
|
|
55
55
|
|
|
56
56
|
existing_indexes = collection.index_information()
|
|
57
57
|
|
|
@@ -59,9 +59,9 @@ def index_exists(collection: Collection, spec: "IndexSpec") -> bool:
|
|
|
59
59
|
# info['key'] can be a list of tuples or a SON/dict object
|
|
60
60
|
raw_existing_key = info["key"]
|
|
61
61
|
if hasattr(raw_existing_key, "items"):
|
|
62
|
-
existing_key = [(str(k),
|
|
62
|
+
existing_key = [(str(k), str(v)) for k, v in raw_existing_key.items()]
|
|
63
63
|
else:
|
|
64
|
-
existing_key = [(str(k),
|
|
64
|
+
existing_key = [(str(k), str(v)) for k, v in raw_existing_key]
|
|
65
65
|
|
|
66
66
|
if existing_key == target_key:
|
|
67
67
|
return True
|
|
File without changes
|
|
File without changes
|
|
File without changes
|