ic-python-db 0.9.0__tar.gz → 0.9.1__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.
- {ic_python_db-0.9.0/ic_python_db.egg-info → ic_python_db-0.9.1}/PKG-INFO +1 -1
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db/__init__.py +1 -1
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db/properties.py +73 -1
- {ic_python_db-0.9.0 → ic_python_db-0.9.1/ic_python_db.egg-info}/PKG-INFO +1 -1
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/pyproject.toml +1 -1
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/setup.py +1 -1
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/LICENSE +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/MANIFEST.in +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/README.md +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db/_cdk.py +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db/constants.py +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db/context.py +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db/db_engine.py +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db/entity.py +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db/hooks.py +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db/mixins.py +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db/py.typed +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db/schema.py +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db/storage.py +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db/system_time.py +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db.egg-info/SOURCES.txt +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db.egg-info/dependency_links.txt +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/ic_python_db.egg-info/top_level.txt +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/requirements-dev.txt +0 -0
- {ic_python_db-0.9.0 → ic_python_db-0.9.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ic-python-db
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.1
|
|
4
4
|
Summary: A lightweight key-value database written in Python, intended for use on the Internet Computer (IC)
|
|
5
5
|
Home-page: https://github.com/smart-social-contracts/ic-python-db
|
|
6
6
|
Author: Smart Social Contracts
|
|
@@ -20,7 +20,7 @@ from .schema import SchemaIncompatibleError, build_schema, diff_schemas, schema_
|
|
|
20
20
|
from .storage import MemoryStorage, Storage
|
|
21
21
|
from .system_time import SystemTime
|
|
22
22
|
|
|
23
|
-
__version__ = "0.9.
|
|
23
|
+
__version__ = "0.9.1"
|
|
24
24
|
__all__ = [
|
|
25
25
|
"Database",
|
|
26
26
|
"Entity",
|
|
@@ -526,6 +526,78 @@ class OneToOne(Relation[E]):
|
|
|
526
526
|
obj._save()
|
|
527
527
|
|
|
528
528
|
|
|
529
|
+
class ManyToManyList(list):
|
|
530
|
+
"""List subclass returned by ManyToMany.__get__ that supports .add() and .remove()."""
|
|
531
|
+
|
|
532
|
+
def __init__(self, items, owner, prop):
|
|
533
|
+
super().__init__(items)
|
|
534
|
+
self._owner = owner
|
|
535
|
+
self._prop = prop
|
|
536
|
+
|
|
537
|
+
def add(self, entity):
|
|
538
|
+
"""Add an entity to this many-to-many relationship."""
|
|
539
|
+
from .db_engine import Database
|
|
540
|
+
from .entity import Entity
|
|
541
|
+
|
|
542
|
+
if isinstance(entity, (str, int)):
|
|
543
|
+
resolved = self._prop.resolve_entity(self._owner, entity)
|
|
544
|
+
elif isinstance(entity, Entity):
|
|
545
|
+
resolved = entity
|
|
546
|
+
else:
|
|
547
|
+
raise TypeError(f"Cannot add {type(entity)} to ManyToMany relation")
|
|
548
|
+
|
|
549
|
+
self._prop.validate_entity(resolved)
|
|
550
|
+
db = Database.get_instance()
|
|
551
|
+
|
|
552
|
+
existing = db.reverse_index_get(
|
|
553
|
+
self._owner._type, self._owner._id, self._prop.name
|
|
554
|
+
)
|
|
555
|
+
if resolved._id not in existing:
|
|
556
|
+
db.reverse_index_add(
|
|
557
|
+
self._owner._type, self._owner._id, self._prop.name, resolved._id
|
|
558
|
+
)
|
|
559
|
+
db.reverse_index_add(
|
|
560
|
+
resolved._type, resolved._id, self._prop.reverse_name, self._owner._id
|
|
561
|
+
)
|
|
562
|
+
if not self._owner._do_not_save:
|
|
563
|
+
self._owner._save()
|
|
564
|
+
self.append(resolved)
|
|
565
|
+
|
|
566
|
+
def discard(self, entity):
|
|
567
|
+
"""Remove an entity from this many-to-many relationship (no error if absent)."""
|
|
568
|
+
from .db_engine import Database
|
|
569
|
+
from .entity import Entity
|
|
570
|
+
|
|
571
|
+
if isinstance(entity, Entity):
|
|
572
|
+
entity_id = entity._id
|
|
573
|
+
entity_type = entity._type
|
|
574
|
+
else:
|
|
575
|
+
entity_id = str(entity)
|
|
576
|
+
entity_type = None
|
|
577
|
+
|
|
578
|
+
db = Database.get_instance()
|
|
579
|
+
db.reverse_index_remove(
|
|
580
|
+
self._owner._type, self._owner._id, self._prop.name, entity_id
|
|
581
|
+
)
|
|
582
|
+
if entity_type:
|
|
583
|
+
db.reverse_index_remove(
|
|
584
|
+
entity_type, entity_id, self._prop.reverse_name, self._owner._id
|
|
585
|
+
)
|
|
586
|
+
else:
|
|
587
|
+
for type_name in self._prop._get_allowed_types():
|
|
588
|
+
db.reverse_index_remove(
|
|
589
|
+
type_name, entity_id, self._prop.reverse_name, self._owner._id
|
|
590
|
+
)
|
|
591
|
+
|
|
592
|
+
self[:] = [e for e in self if getattr(e, "_id", None) != entity_id]
|
|
593
|
+
if not self._owner._do_not_save:
|
|
594
|
+
self._owner._save()
|
|
595
|
+
|
|
596
|
+
def remove(self, entity):
|
|
597
|
+
"""Remove an entity from this many-to-many relationship."""
|
|
598
|
+
self.discard(entity)
|
|
599
|
+
|
|
600
|
+
|
|
529
601
|
class ManyToMany(Relation[E]):
|
|
530
602
|
"""Many-to-many relationship with bidirectional reverse indexes.
|
|
531
603
|
|
|
@@ -562,7 +634,7 @@ class ManyToMany(Relation[E]):
|
|
|
562
634
|
if entity:
|
|
563
635
|
entities.append(entity)
|
|
564
636
|
break
|
|
565
|
-
return entities # type: ignore[return-value]
|
|
637
|
+
return ManyToManyList(entities, obj, self) # type: ignore[return-value]
|
|
566
638
|
|
|
567
639
|
def __set__(self, obj, values):
|
|
568
640
|
from .db_engine import Database
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ic-python-db
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.1
|
|
4
4
|
Summary: A lightweight key-value database written in Python, intended for use on the Internet Computer (IC)
|
|
5
5
|
Home-page: https://github.com/smart-social-contracts/ic-python-db
|
|
6
6
|
Author: Smart Social Contracts
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ic-python-db"
|
|
7
|
-
version = "0.9.
|
|
7
|
+
version = "0.9.1"
|
|
8
8
|
description = "A lightweight key-value database written in Python, intended for use on the Internet Computer (IC)"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name="ic-python-db",
|
|
8
|
-
version="0.9.
|
|
8
|
+
version="0.9.1",
|
|
9
9
|
author="Smart Social Contracts",
|
|
10
10
|
author_email="smartsocialcontracts@gmail.com",
|
|
11
11
|
description="A lightweight key-value database with entity relationships and audit logging",
|
|
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
|
|
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
|