sql-athame 0.4.0a3__py3-none-any.whl → 0.4.0a5__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.
sql_athame/dataclasses.py CHANGED
@@ -440,6 +440,7 @@ class ModelBase(Mapping[str, Any]):
440
440
  async def insert_multiple_array_safe(
441
441
  cls: Type[T], connection_or_pool: Union[Connection, Pool], rows: Iterable[T]
442
442
  ) -> str:
443
+ last = ""
443
444
  for chunk in chunked(rows, 100):
444
445
  last = await connection_or_pool.execute(
445
446
  *cls.insert_multiple_array_safe_sql(chunk)
@@ -457,30 +458,46 @@ class ModelBase(Mapping[str, Any]):
457
458
 
458
459
  @classmethod
459
460
  async def upsert_multiple_unnest(
460
- cls: Type[T], connection_or_pool: Union[Connection, Pool], rows: Iterable[T]
461
+ cls: Type[T],
462
+ connection_or_pool: Union[Connection, Pool],
463
+ rows: Iterable[T],
464
+ insert_only: FieldNamesSet = (),
461
465
  ) -> str:
462
466
  return await connection_or_pool.execute(
463
- *cls.upsert_sql(cls.insert_multiple_sql(rows))
467
+ *cls.upsert_sql(cls.insert_multiple_sql(rows), exclude=insert_only)
464
468
  )
465
469
 
466
470
  @classmethod
467
471
  async def upsert_multiple_array_safe(
468
- cls: Type[T], connection_or_pool: Union[Connection, Pool], rows: Iterable[T]
472
+ cls: Type[T],
473
+ connection_or_pool: Union[Connection, Pool],
474
+ rows: Iterable[T],
475
+ insert_only: FieldNamesSet = (),
469
476
  ) -> str:
477
+ last = ""
470
478
  for chunk in chunked(rows, 100):
471
479
  last = await connection_or_pool.execute(
472
- *cls.upsert_sql(cls.insert_multiple_array_safe_sql(chunk))
480
+ *cls.upsert_sql(
481
+ cls.insert_multiple_array_safe_sql(chunk), exclude=insert_only
482
+ )
473
483
  )
474
484
  return last
475
485
 
476
486
  @classmethod
477
487
  async def upsert_multiple(
478
- cls: Type[T], connection_or_pool: Union[Connection, Pool], rows: Iterable[T]
488
+ cls: Type[T],
489
+ connection_or_pool: Union[Connection, Pool],
490
+ rows: Iterable[T],
491
+ insert_only: FieldNamesSet = (),
479
492
  ) -> str:
480
493
  if cls.array_safe_insert:
481
- return await cls.upsert_multiple_array_safe(connection_or_pool, rows)
494
+ return await cls.upsert_multiple_array_safe(
495
+ connection_or_pool, rows, insert_only=insert_only
496
+ )
482
497
  else:
483
- return await cls.upsert_multiple_unnest(connection_or_pool, rows)
498
+ return await cls.upsert_multiple_unnest(
499
+ connection_or_pool, rows, insert_only=insert_only
500
+ )
484
501
 
485
502
  @classmethod
486
503
  def _get_equal_ignoring_fn(
@@ -503,9 +520,11 @@ class ModelBase(Mapping[str, Any]):
503
520
  *,
504
521
  where: Where,
505
522
  ignore: FieldNamesSet = (),
523
+ insert_only: FieldNamesSet = (),
506
524
  ) -> Tuple[List[T], List[T], List[T]]:
525
+ ignore = sorted(set(ignore) | set(insert_only))
507
526
  equal_ignoring = cls._cached(
508
- ("equal_ignoring", tuple(sorted(ignore))),
527
+ ("equal_ignoring", tuple(ignore)),
509
528
  lambda: cls._get_equal_ignoring_fn(ignore),
510
529
  )
511
530
  pending = {row.primary_key(): row for row in map(cls.ensure_model, rows)}
@@ -527,7 +546,9 @@ class ModelBase(Mapping[str, Any]):
527
546
  created = list(pending.values())
528
547
 
529
548
  if created or updated:
530
- await cls.upsert_multiple(connection, (*created, *updated))
549
+ await cls.upsert_multiple(
550
+ connection, (*created, *updated), insert_only=insert_only
551
+ )
531
552
  if deleted:
532
553
  await cls.delete_multiple(connection, deleted)
533
554
 
@@ -559,9 +580,11 @@ class ModelBase(Mapping[str, Any]):
559
580
  *,
560
581
  where: Where,
561
582
  ignore: FieldNamesSet = (),
583
+ insert_only: FieldNamesSet = (),
562
584
  ) -> Tuple[List[T], List[Tuple[T, T, List[str]]], List[T]]:
585
+ ignore = sorted(set(ignore) | set(insert_only))
563
586
  differences_ignoring = cls._cached(
564
- ("differences_ignoring", tuple(sorted(ignore))),
587
+ ("differences_ignoring", tuple(ignore)),
565
588
  lambda: cls._get_differences_ignoring_fn(ignore),
566
589
  )
567
590
 
@@ -586,7 +609,9 @@ class ModelBase(Mapping[str, Any]):
586
609
 
587
610
  if created or updated_triples:
588
611
  await cls.upsert_multiple(
589
- connection, (*created, *(t[1] for t in updated_triples))
612
+ connection,
613
+ (*created, *(t[1] for t in updated_triples)),
614
+ insert_only=insert_only,
590
615
  )
591
616
  if deleted:
592
617
  await cls.delete_multiple(connection, deleted)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql-athame
3
- Version: 0.4.0a3
3
+ Version: 0.4.0a5
4
4
  Summary: Python tool for slicing and dicing SQL
5
5
  Home-page: https://github.com/bdowning/sql-athame
6
6
  License: MIT
@@ -1,11 +1,11 @@
1
1
  sql_athame/__init__.py,sha256=rzUQcbzmj3qkPZpL9jI_ALTRv-e1pAV4jSCryWkutlk,130
2
2
  sql_athame/base.py,sha256=fSnHQhh5ULeJ5q32RVUAvpWtF0qoY61B2gEEP59Nrpo,10350
3
- sql_athame/dataclasses.py,sha256=qMs5xCuYwBjPYOD3EdRR9p4Bc3ZqoRsOmD1urDYVvH0,19751
3
+ sql_athame/dataclasses.py,sha256=KTn8bUBajNXDDVxgoBF7BdFkv8gSQynfa8fyYv8WrzM,20442
4
4
  sql_athame/escape.py,sha256=LXExbiYtc407yDU4vPieyY2Pq5nypsJFfBc_2-gsbUg,743
5
5
  sql_athame/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  sql_athame/sqlalchemy.py,sha256=c-pCLE11hTh5I19rY1Vp5E7P7lAaj9i-i7ko2L8rlF4,1305
7
7
  sql_athame/types.py,sha256=7P4OyY0ezRlb2UDD9lpdXiLChnhQcBvHWaG_PKy3jmE,412
8
- sql_athame-0.4.0a3.dist-info/LICENSE,sha256=xqV29vPFqITcKifYrGPgVIBjq4fdmLSwY3gRUtDKafg,1076
9
- sql_athame-0.4.0a3.dist-info/METADATA,sha256=ww5zr5Vvsn2SDrKZU6Er-xahTj091zKXpGTVv4EarV8,12845
10
- sql_athame-0.4.0a3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
11
- sql_athame-0.4.0a3.dist-info/RECORD,,
8
+ sql_athame-0.4.0a5.dist-info/LICENSE,sha256=xqV29vPFqITcKifYrGPgVIBjq4fdmLSwY3gRUtDKafg,1076
9
+ sql_athame-0.4.0a5.dist-info/METADATA,sha256=-9SuyMtbLf8Dl4oHXKPRrIGRyuVcVPc2Yt5B3958zNo,12845
10
+ sql_athame-0.4.0a5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
11
+ sql_athame-0.4.0a5.dist-info/RECORD,,