half-orm 0.18.14__tar.gz → 0.18.15__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.
- {half_orm-0.18.14/half_orm.egg-info → half_orm-0.18.15}/PKG-INFO +1 -1
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/relation.py +16 -2
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/sql_ast.py +8 -2
- half_orm-0.18.15/half_orm/version.txt +1 -0
- {half_orm-0.18.14 → half_orm-0.18.15/half_orm.egg-info}/PKG-INFO +1 -1
- {half_orm-0.18.14 → half_orm-0.18.15}/test/test_sql_ast.py +12 -0
- half_orm-0.18.14/half_orm/version.txt +0 -1
- {half_orm-0.18.14 → half_orm-0.18.15}/AUTHORS +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/LICENSE +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/README.md +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/__init__.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/__main__.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/cli.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/cli_utils.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/field.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/field_errors.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/fkey.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/hotest.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/model.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/model_errors.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/null.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/pg_meta.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/relation_errors.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/relation_factory.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/sql_adapter.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/transaction.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm/utils.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm.egg-info/SOURCES.txt +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm.egg-info/dependency_links.txt +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm.egg-info/entry_points.txt +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm.egg-info/requires.txt +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/half_orm.egg-info/top_level.txt +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/pyproject.toml +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/setup.cfg +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/setup.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/test/test_cli.py +0 -0
- {half_orm-0.18.14 → half_orm-0.18.15}/test/test_main.py +0 -0
|
@@ -676,6 +676,20 @@ class Relation:
|
|
|
676
676
|
return where, values
|
|
677
677
|
|
|
678
678
|
#@utils.trace
|
|
679
|
+
def _ho_writes_through_subquery(self):
|
|
680
|
+
"""True when UPDATE and DELETE must select their rows with a subquery.
|
|
681
|
+
|
|
682
|
+
That is the case when the predicate carries FK joins, and when it is
|
|
683
|
+
a UNION or EXCEPT container built by ``|`` or ``-`` (see ``__or__``
|
|
684
|
+
and ``__sub__``): such a container has no join of its own, its
|
|
685
|
+
operands do, and only the SELECT compiler knows how to combine them.
|
|
686
|
+
Writing with the operands' WHERE clauses alone would drop their joins
|
|
687
|
+
and touch rows outside the predicate.
|
|
688
|
+
"""
|
|
689
|
+
return bool(self._ho_join_to
|
|
690
|
+
or self._ho_union_branches is not None
|
|
691
|
+
or self._ho_except_branches is not None)
|
|
692
|
+
|
|
679
693
|
def _ho_prep_update(self, *args, update_all=False, **kwargs):
|
|
680
694
|
"""Prepare an UPDATE query. Returns (query, vals, update_args) or None if nothing to update."""
|
|
681
695
|
self._ho_check_writable()
|
|
@@ -693,7 +707,7 @@ class Relation:
|
|
|
693
707
|
for field_name, new_value in update_args.items():
|
|
694
708
|
col_name = self._ho_fields[field_name].name
|
|
695
709
|
set_clause.append((f'"{col_name}" = %s', new_value))
|
|
696
|
-
if self.
|
|
710
|
+
if self._ho_writes_through_subquery():
|
|
697
711
|
# Build a subquery to avoid any DB round-trip and to correctly
|
|
698
712
|
# propagate JOIN constraints into the UPDATE predicate.
|
|
699
713
|
pk_names = list(self._ho_pkey.keys())
|
|
@@ -773,7 +787,7 @@ class Relation:
|
|
|
773
787
|
f'Attempt to delete all rows from {self.__class__.__name__}'
|
|
774
788
|
' without delete_all being set to True!')
|
|
775
789
|
self._ho_query_type = 'delete'
|
|
776
|
-
if self.
|
|
790
|
+
if self._ho_writes_through_subquery():
|
|
777
791
|
# Build a subquery to avoid any DB round-trip and to correctly
|
|
778
792
|
# propagate JOIN constraints into the DELETE predicate.
|
|
779
793
|
pk_names = list(self._ho_pkey.keys())
|
|
@@ -308,7 +308,8 @@ class Insert:
|
|
|
308
308
|
table : str
|
|
309
309
|
Fully qualified table name (no alias).
|
|
310
310
|
columns : list[str]
|
|
311
|
-
Column names to insert into.
|
|
311
|
+
Column names to insert into. Empty, every column takes its default
|
|
312
|
+
(``DEFAULT VALUES``).
|
|
312
313
|
placeholders : list[str]
|
|
313
314
|
One ``%s`` per column (may include sub-selects for FK values).
|
|
314
315
|
values : list
|
|
@@ -324,7 +325,12 @@ class Insert:
|
|
|
324
325
|
def to_sql(self) -> Tuple[str, list]:
|
|
325
326
|
cols = ", ".join(self.columns)
|
|
326
327
|
phs = ", ".join(self.placeholders)
|
|
327
|
-
|
|
328
|
+
if self.columns:
|
|
329
|
+
sql = f"insert into {self.table} ({cols}) values ({phs})"
|
|
330
|
+
else:
|
|
331
|
+
# No field set: every column takes its default. "() values ()" is
|
|
332
|
+
# not SQL.
|
|
333
|
+
sql = f"insert into {self.table} default values"
|
|
328
334
|
if self.returning:
|
|
329
335
|
sql += self.returning.to_sql()
|
|
330
336
|
return sql, list(self.values)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.18.15
|
|
@@ -312,6 +312,18 @@ class TestInsert(unittest.TestCase):
|
|
|
312
312
|
self.assertEqual(sql, 'insert into "public"."person" ("name", "age") values (%s, %s)')
|
|
313
313
|
self.assertEqual(vals, ["Alice", 30])
|
|
314
314
|
|
|
315
|
+
def test_no_column_inserts_default_values(self):
|
|
316
|
+
stmt = Insert(
|
|
317
|
+
table='"public"."person"',
|
|
318
|
+
columns=[],
|
|
319
|
+
placeholders=[],
|
|
320
|
+
values=[],
|
|
321
|
+
returning=Returning(["*"]),
|
|
322
|
+
)
|
|
323
|
+
sql, vals = stmt.to_sql()
|
|
324
|
+
self.assertEqual(sql, 'insert into "public"."person" default values returning *')
|
|
325
|
+
self.assertEqual(vals, [])
|
|
326
|
+
|
|
315
327
|
def test_with_returning(self):
|
|
316
328
|
stmt = Insert(
|
|
317
329
|
table='"public"."person"',
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.18.14
|
|
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
|
|
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
|