sql-athame 0.4.0a4__tar.gz → 0.4.0a5__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql-athame
3
- Version: 0.4.0a4
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,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "sql-athame"
3
- version = "0.4.0-alpha-4"
3
+ version = "0.4.0-alpha-5"
4
4
  description = "Python tool for slicing and dicing SQL"
5
5
  authors = ["Brian Downing <bdowning@lavos.net>"]
6
6
  license = "MIT"
@@ -458,31 +458,46 @@ class ModelBase(Mapping[str, Any]):
458
458
 
459
459
  @classmethod
460
460
  async def upsert_multiple_unnest(
461
- 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 = (),
462
465
  ) -> str:
463
466
  return await connection_or_pool.execute(
464
- *cls.upsert_sql(cls.insert_multiple_sql(rows))
467
+ *cls.upsert_sql(cls.insert_multiple_sql(rows), exclude=insert_only)
465
468
  )
466
469
 
467
470
  @classmethod
468
471
  async def upsert_multiple_array_safe(
469
- 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 = (),
470
476
  ) -> str:
471
477
  last = ""
472
478
  for chunk in chunked(rows, 100):
473
479
  last = await connection_or_pool.execute(
474
- *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
+ )
475
483
  )
476
484
  return last
477
485
 
478
486
  @classmethod
479
487
  async def upsert_multiple(
480
- 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 = (),
481
492
  ) -> str:
482
493
  if cls.array_safe_insert:
483
- 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
+ )
484
497
  else:
485
- 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
+ )
486
501
 
487
502
  @classmethod
488
503
  def _get_equal_ignoring_fn(
@@ -505,9 +520,11 @@ class ModelBase(Mapping[str, Any]):
505
520
  *,
506
521
  where: Where,
507
522
  ignore: FieldNamesSet = (),
523
+ insert_only: FieldNamesSet = (),
508
524
  ) -> Tuple[List[T], List[T], List[T]]:
525
+ ignore = sorted(set(ignore) | set(insert_only))
509
526
  equal_ignoring = cls._cached(
510
- ("equal_ignoring", tuple(sorted(ignore))),
527
+ ("equal_ignoring", tuple(ignore)),
511
528
  lambda: cls._get_equal_ignoring_fn(ignore),
512
529
  )
513
530
  pending = {row.primary_key(): row for row in map(cls.ensure_model, rows)}
@@ -529,7 +546,9 @@ class ModelBase(Mapping[str, Any]):
529
546
  created = list(pending.values())
530
547
 
531
548
  if created or updated:
532
- await cls.upsert_multiple(connection, (*created, *updated))
549
+ await cls.upsert_multiple(
550
+ connection, (*created, *updated), insert_only=insert_only
551
+ )
533
552
  if deleted:
534
553
  await cls.delete_multiple(connection, deleted)
535
554
 
@@ -561,9 +580,11 @@ class ModelBase(Mapping[str, Any]):
561
580
  *,
562
581
  where: Where,
563
582
  ignore: FieldNamesSet = (),
583
+ insert_only: FieldNamesSet = (),
564
584
  ) -> Tuple[List[T], List[Tuple[T, T, List[str]]], List[T]]:
585
+ ignore = sorted(set(ignore) | set(insert_only))
565
586
  differences_ignoring = cls._cached(
566
- ("differences_ignoring", tuple(sorted(ignore))),
587
+ ("differences_ignoring", tuple(ignore)),
567
588
  lambda: cls._get_differences_ignoring_fn(ignore),
568
589
  )
569
590
 
@@ -588,7 +609,9 @@ class ModelBase(Mapping[str, Any]):
588
609
 
589
610
  if created or updated_triples:
590
611
  await cls.upsert_multiple(
591
- 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,
592
615
  )
593
616
  if deleted:
594
617
  await cls.delete_multiple(connection, deleted)
File without changes
File without changes