sql-athame 0.4.0a9__tar.gz → 0.4.0a10__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.
- {sql_athame-0.4.0a9 → sql_athame-0.4.0a10}/PKG-INFO +1 -1
- {sql_athame-0.4.0a9 → sql_athame-0.4.0a10}/pyproject.toml +1 -1
- sql_athame-0.4.0a10/sql_athame/__init__.py +2 -0
- {sql_athame-0.4.0a9 → sql_athame-0.4.0a10}/sql_athame/dataclasses.py +47 -10
- sql_athame-0.4.0a9/sql_athame/__init__.py +0 -2
- {sql_athame-0.4.0a9 → sql_athame-0.4.0a10}/LICENSE +0 -0
- {sql_athame-0.4.0a9 → sql_athame-0.4.0a10}/README.md +0 -0
- {sql_athame-0.4.0a9 → sql_athame-0.4.0a10}/sql_athame/base.py +0 -0
- {sql_athame-0.4.0a9 → sql_athame-0.4.0a10}/sql_athame/escape.py +0 -0
- {sql_athame-0.4.0a9 → sql_athame-0.4.0a10}/sql_athame/py.typed +0 -0
- {sql_athame-0.4.0a9 → sql_athame-0.4.0a10}/sql_athame/sqlalchemy.py +0 -0
- {sql_athame-0.4.0a9 → sql_athame-0.4.0a10}/sql_athame/types.py +0 -0
@@ -8,6 +8,7 @@ from typing import (
|
|
8
8
|
Annotated,
|
9
9
|
Any,
|
10
10
|
Callable,
|
11
|
+
Generic,
|
11
12
|
Optional,
|
12
13
|
TypeVar,
|
13
14
|
Union,
|
@@ -251,7 +252,7 @@ class ModelBase:
|
|
251
252
|
if ci.field.name not in exclude:
|
252
253
|
if ci.serialize:
|
253
254
|
env[f"_ser_{ci.field.name}"] = ci.serialize
|
254
|
-
func.append(f"_ser_{ci.field.name}(self.{ci.field.name}),
|
255
|
+
func.append(f"_ser_{ci.field.name}(self.{ci.field.name}),")
|
255
256
|
else:
|
256
257
|
func.append(f"self.{ci.field.name},")
|
257
258
|
func += ["]"]
|
@@ -588,7 +589,7 @@ class ModelBase:
|
|
588
589
|
return env["equal_ignoring"]
|
589
590
|
|
590
591
|
@classmethod
|
591
|
-
async def
|
592
|
+
async def plan_replace_multiple(
|
592
593
|
cls: type[T],
|
593
594
|
connection: Connection,
|
594
595
|
rows: Union[Iterable[T], Iterable[Mapping[str, Any]]],
|
@@ -596,7 +597,7 @@ class ModelBase:
|
|
596
597
|
where: Where,
|
597
598
|
ignore: FieldNamesSet = (),
|
598
599
|
insert_only: FieldNamesSet = (),
|
599
|
-
) ->
|
600
|
+
) -> "ReplaceMultiplePlan[T]":
|
600
601
|
ignore = sorted(set(ignore) | set(insert_only))
|
601
602
|
equal_ignoring = cls._cached(
|
602
603
|
("equal_ignoring", tuple(ignore)),
|
@@ -620,14 +621,23 @@ class ModelBase:
|
|
620
621
|
|
621
622
|
created = list(pending.values())
|
622
623
|
|
623
|
-
|
624
|
-
await cls.upsert_multiple(
|
625
|
-
connection, (*created, *updated), insert_only=insert_only
|
626
|
-
)
|
627
|
-
if deleted:
|
628
|
-
await cls.delete_multiple(connection, deleted)
|
624
|
+
return ReplaceMultiplePlan(cls, insert_only, created, updated, deleted)
|
629
625
|
|
630
|
-
|
626
|
+
@classmethod
|
627
|
+
async def replace_multiple(
|
628
|
+
cls: type[T],
|
629
|
+
connection: Connection,
|
630
|
+
rows: Union[Iterable[T], Iterable[Mapping[str, Any]]],
|
631
|
+
*,
|
632
|
+
where: Where,
|
633
|
+
ignore: FieldNamesSet = (),
|
634
|
+
insert_only: FieldNamesSet = (),
|
635
|
+
) -> tuple[list[T], list[T], list[T]]:
|
636
|
+
plan = await cls.plan_replace_multiple(
|
637
|
+
connection, rows, where=where, ignore=ignore, insert_only=insert_only
|
638
|
+
)
|
639
|
+
await plan.execute(connection)
|
640
|
+
return plan.cud
|
631
641
|
|
632
642
|
@classmethod
|
633
643
|
def _get_differences_ignoring_fn(
|
@@ -694,6 +704,33 @@ class ModelBase:
|
|
694
704
|
return created, updated_triples, deleted
|
695
705
|
|
696
706
|
|
707
|
+
@dataclass
|
708
|
+
class ReplaceMultiplePlan(Generic[T]):
|
709
|
+
model_class: type[T]
|
710
|
+
insert_only: FieldNamesSet
|
711
|
+
created: list[T]
|
712
|
+
updated: list[T]
|
713
|
+
deleted: list[T]
|
714
|
+
|
715
|
+
@property
|
716
|
+
def cud(self) -> tuple[list[T], list[T], list[T]]:
|
717
|
+
return (self.created, self.updated, self.deleted)
|
718
|
+
|
719
|
+
async def execute_upserts(self, connection: Connection) -> None:
|
720
|
+
if self.created or self.updated:
|
721
|
+
await self.model_class.upsert_multiple(
|
722
|
+
connection, (*self.created, *self.updated), insert_only=self.insert_only
|
723
|
+
)
|
724
|
+
|
725
|
+
async def execute_deletes(self, connection: Connection) -> None:
|
726
|
+
if self.deleted:
|
727
|
+
await self.model_class.delete_multiple(connection, self.deleted)
|
728
|
+
|
729
|
+
async def execute(self, connection: Connection) -> None:
|
730
|
+
await self.execute_upserts(connection)
|
731
|
+
await self.execute_deletes(connection)
|
732
|
+
|
733
|
+
|
697
734
|
def chunked(lst, n):
|
698
735
|
if type(lst) is not list:
|
699
736
|
lst = list(lst)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|