diff options
| author | Abdulhaq Emhemmed <el.ingeniero09@gmail.com> | 2023-02-10 22:56:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-10 22:56:30 +0100 |
| commit | b95b22d8c0f9f26e33e1912d8ee205319fc20362 (patch) | |
| tree | aa696fb467f02930ee9a2f2e7e2d0b2e3b6814b5 | |
| parent | 7959d30aaa1c760d8585fc9a0375b06e0dcbe4dd (diff) | |
| download | sqlalchemy-b95b22d8c0f9f26e33e1912d8ee205319fc20362.tar.gz | |
Fix docs for `case` expression to match new syntax (#9279)
* Fix docs for `case` expression to match new syntax
Previously (before v1.4), the `whens` arg (when `value` is *not* used) used to be a list of
conditions (a 2 item-tuple of condition + value). From v1.4, these are passed
as positional args and the old syntax is not supported anymore.
* Fix long lines
| -rw-r--r-- | lib/sqlalchemy/ext/compiler.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/_elements_constructors.py | 8 |
3 files changed, 7 insertions, 7 deletions
diff --git a/lib/sqlalchemy/ext/compiler.py b/lib/sqlalchemy/ext/compiler.py index 54a99cced..39a554103 100644 --- a/lib/sqlalchemy/ext/compiler.py +++ b/lib/sqlalchemy/ext/compiler.py @@ -409,7 +409,7 @@ accommodates two arguments:: @compiles(greatest, 'oracle') def case_greatest(element, compiler, **kw): arg1, arg2 = list(element.clauses) - return compiler.process(case([(arg1 > arg2, arg1)], else_=arg2), **kw) + return compiler.process(case((arg1 > arg2, arg1), else_=arg2), **kw) Example usage:: diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 092ab1cda..c0ff2ed10 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -565,10 +565,10 @@ class Mapper( discriminator: Mapped[str] = mapped_column(String(50)) __mapper_args__ = { - "polymorphic_on":case([ + "polymorphic_on":case( (discriminator == "EN", "engineer"), (discriminator == "MA", "manager"), - ], else_="employee"), + else_="employee"), "polymorphic_identity":"employee" } diff --git a/lib/sqlalchemy/sql/_elements_constructors.py b/lib/sqlalchemy/sql/_elements_constructors.py index 98f5a1cc6..5c7019718 100644 --- a/lib/sqlalchemy/sql/_elements_constructors.py +++ b/lib/sqlalchemy/sql/_elements_constructors.py @@ -757,10 +757,10 @@ def case( .. versionchanged:: 1.4 the :func:`_sql.case` function now accepts the series of WHEN conditions positionally - In the first form, it accepts a list of 2-tuples; each 2-tuple - consists of ``(<sql expression>, <value>)``, where the SQL - expression is a boolean expression and "value" is a resulting value, - e.g.:: + In the first form, it accepts multiple 2-tuples passed as positional + arguments; each 2-tuple consists of ``(<sql expression>, <value>)``, + where the SQL expression is a boolean expression and "value" is a + resulting value, e.g.:: case( (users_table.c.name == 'wendy', 'W'), |
