half-orm 1.2.1__tar.gz → 1.2.2__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.
Files changed (41) hide show
  1. {half_orm-1.2.1/half_orm.egg-info → half_orm-1.2.2}/PKG-INFO +1 -1
  2. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/relation.py +16 -2
  3. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/sql_ast.py +8 -2
  4. half_orm-1.2.2/half_orm/version.txt +1 -0
  5. {half_orm-1.2.1 → half_orm-1.2.2/half_orm.egg-info}/PKG-INFO +1 -1
  6. {half_orm-1.2.1 → half_orm-1.2.2}/pyproject.toml +1 -1
  7. {half_orm-1.2.1 → half_orm-1.2.2}/test/test_sql_ast.py +12 -0
  8. half_orm-1.2.1/half_orm/version.txt +0 -1
  9. {half_orm-1.2.1 → half_orm-1.2.2}/AUTHORS +0 -0
  10. {half_orm-1.2.1 → half_orm-1.2.2}/LICENSE +0 -0
  11. {half_orm-1.2.1 → half_orm-1.2.2}/README.md +0 -0
  12. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/__init__.py +0 -0
  13. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/__main__.py +0 -0
  14. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/_predicate.py +0 -0
  15. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/cli.py +0 -0
  16. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/cli_utils.py +0 -0
  17. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/field.py +0 -0
  18. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/field_errors.py +0 -0
  19. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/fkey.py +0 -0
  20. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/hotest.py +0 -0
  21. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/migrations/BREAKING_CHANGES-1.0.0.md +0 -0
  22. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/migrations/__init__.py +0 -0
  23. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/model.py +0 -0
  24. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/model_errors.py +0 -0
  25. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/null.py +0 -0
  26. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/pg_meta.py +0 -0
  27. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/py.typed +0 -0
  28. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/relation_errors.py +0 -0
  29. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/relation_factory.py +0 -0
  30. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/sql_adapter.py +0 -0
  31. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/testing.py +0 -0
  32. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/transaction.py +0 -0
  33. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm/utils.py +0 -0
  34. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm.egg-info/SOURCES.txt +0 -0
  35. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm.egg-info/dependency_links.txt +0 -0
  36. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm.egg-info/entry_points.txt +0 -0
  37. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm.egg-info/requires.txt +0 -0
  38. {half_orm-1.2.1 → half_orm-1.2.2}/half_orm.egg-info/top_level.txt +0 -0
  39. {half_orm-1.2.1 → half_orm-1.2.2}/setup.cfg +0 -0
  40. {half_orm-1.2.1 → half_orm-1.2.2}/test/test_cli.py +0 -0
  41. {half_orm-1.2.1 → half_orm-1.2.2}/test/test_main.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: half_orm
3
- Version: 1.2.1
3
+ Version: 1.2.2
4
4
  Summary: A database-first ORM for PostgreSQL
5
5
  Author-email: Joël Maïzi <joel.maizi@collorg.org>
6
6
  License-Expression: GPL-3.0-or-later
@@ -908,6 +908,20 @@ class Relation:
908
908
  return where, values
909
909
 
910
910
  #@utils.trace
911
+ def _ho_writes_through_subquery(self):
912
+ """True when UPDATE and DELETE must select their rows with a subquery.
913
+
914
+ That is the case when the predicate carries FK joins, and when it is
915
+ a UNION or EXCEPT container built by ``|`` or ``-`` (see ``__or__``
916
+ and ``__sub__``): such a container has no join of its own, its
917
+ operands do, and only the SELECT compiler knows how to combine them.
918
+ Writing with the operands' WHERE clauses alone would drop their joins
919
+ and touch rows outside the predicate.
920
+ """
921
+ return bool(self._ho_join_to
922
+ or self._ho_union_branches is not None
923
+ or self._ho_except_branches is not None)
924
+
911
925
  def _ho_prep_update(self, *args, update_all=False, **kwargs):
912
926
  """Prepare an UPDATE query. Returns (query, vals, update_args) or None if nothing to update."""
913
927
  self._ho_check_writable()
@@ -925,7 +939,7 @@ class Relation:
925
939
  for field_name, new_value in update_args.items():
926
940
  col_name = self._ho_fields[field_name].name
927
941
  set_clause.append((f'{_ho_quote_ident(col_name)} = %s', new_value))
928
- if self._ho_join_to:
942
+ if self._ho_writes_through_subquery():
929
943
  # Build a subquery to avoid any DB round-trip and to correctly
930
944
  # propagate JOIN constraints into the UPDATE predicate.
931
945
  pk_names = list(self._ho_pkey.keys())
@@ -1010,7 +1024,7 @@ class Relation:
1010
1024
  f'Attempt to delete all rows from {self.__class__.__name__}'
1011
1025
  ' without delete_all being set to True!')
1012
1026
  self._ho_query_type = 'delete'
1013
- if self._ho_join_to:
1027
+ if self._ho_writes_through_subquery():
1014
1028
  # Build a subquery to avoid any DB round-trip and to correctly
1015
1029
  # propagate JOIN constraints into the DELETE predicate.
1016
1030
  pk_names = list(self._ho_pkey.keys())
@@ -294,7 +294,8 @@ class Insert:
294
294
  table : str
295
295
  Fully qualified table name (no alias).
296
296
  columns : list[str]
297
- Column names to insert into.
297
+ Column names to insert into. Empty, every column takes its default
298
+ (``DEFAULT VALUES``).
298
299
  placeholders : list[str]
299
300
  One ``%s`` per column (may include sub-selects for FK values).
300
301
  values : list
@@ -313,7 +314,12 @@ class Insert:
313
314
  cols = ", ".join(self.columns)
314
315
  phs = ", ".join(self.placeholders)
315
316
  values = list(self.values)
316
- sql = f"insert into {self.table} ({cols}) values ({phs})"
317
+ if self.columns:
318
+ sql = f"insert into {self.table} ({cols}) values ({phs})"
319
+ else:
320
+ # No field set: every column takes its default. "() values ()" is
321
+ # not SQL.
322
+ sql = f"insert into {self.table} default values"
317
323
  if self.upsert:
318
324
  conflict_target = ", ".join(self.pk_columns or self.columns)
319
325
  non_pk = [c for c in self.columns if c not in (self.pk_columns or [])]
@@ -0,0 +1 @@
1
+ 1.2.2
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: half_orm
3
- Version: 1.2.1
3
+ Version: 1.2.2
4
4
  Summary: A database-first ORM for PostgreSQL
5
5
  Author-email: Joël Maïzi <joel.maizi@collorg.org>
6
6
  License-Expression: GPL-3.0-or-later
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"
4
4
 
5
5
  [project]
6
6
  name = "half_orm"
7
- version = "1.2.1"
7
+ version = "1.2.2"
8
8
  description = "A database-first ORM for PostgreSQL"
9
9
  readme = "README.md"
10
10
  license = "GPL-3.0-or-later"
@@ -313,6 +313,18 @@ class TestInsert(unittest.TestCase):
313
313
  self.assertEqual(sql, 'insert into "public"."person" ("name", "age") values (%s, %s) on conflict ("name", "age") do update set "name" = %s, "age" = %s')
314
314
  self.assertEqual(vals, ["Alice", 30, "Alice", 30])
315
315
 
316
+ def test_no_column_inserts_default_values(self):
317
+ stmt = Insert(
318
+ table='"public"."person"',
319
+ columns=[],
320
+ placeholders=[],
321
+ values=[],
322
+ returning=Returning(["*"]),
323
+ )
324
+ sql, vals = stmt.to_sql()
325
+ self.assertEqual(sql, 'insert into "public"."person" default values returning *')
326
+ self.assertEqual(vals, [])
327
+
316
328
  def test_with_returning(self):
317
329
  stmt = Insert(
318
330
  table='"public"."person"',
@@ -1 +0,0 @@
1
- 1.2.1
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