diff options
| author | Federico Caselli <cfederico87@gmail.com> | 2020-09-02 23:46:06 +0200 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-09-08 17:13:48 -0400 |
| commit | e8600608669d90c4a6385b312d271aed63eb5854 (patch) | |
| tree | ef984a01c536b2c81d2283b3ca5d9f4395f41dd0 /examples | |
| parent | 0d56a62f721ee6c91d8a8b6a407b959c9215b3b6 (diff) | |
| download | sqlalchemy-e8600608669d90c4a6385b312d271aed63eb5854.tar.gz | |
Update select usage to use the new 1.4 format
This change includes mainly that the bracketed use within
select() is moved to positional, and keyword arguments are
removed from calls to the select() function. it does not
yet fully address other issues such as keyword arguments passed
to the table.select().
Additionally, allows False / None to both be considered
as "disable" for all of select.correlate(), select.correlate_except(),
query.correlate(), which establishes consistency with
passing of ``False`` for the legact select(correlate=False)
argument.
Change-Id: Ie6c6e6abfbd3d75d4c8de504c0cf0159e6999108
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/materialized_paths/materialized_paths.py | 20 | ||||
| -rw-r--r-- | examples/nested_sets/nested_sets.py | 2 | ||||
| -rw-r--r-- | examples/performance/short_selects.py | 8 | ||||
| -rw-r--r-- | examples/postgis/postgis.py | 36 | ||||
| -rw-r--r-- | examples/versioned_history/test_versioning.py | 4 | ||||
| -rw-r--r-- | examples/versioned_rows/versioned_rows_w_versionid.py | 2 |
6 files changed, 32 insertions, 40 deletions
diff --git a/examples/materialized_paths/materialized_paths.py b/examples/materialized_paths/materialized_paths.py index f777f131b..37e91684c 100644 --- a/examples/materialized_paths/materialized_paths.py +++ b/examples/materialized_paths/materialized_paths.py @@ -62,17 +62,15 @@ class Node(Base): # Finding the ancestors is a little bit trickier. We need to create a fake # secondary table since this behaves like a many-to-many join. secondary = select( - [ - id.label("id"), - func.unnest( - cast( - func.string_to_array( - func.regexp_replace(path, r"\.?\d+$", ""), "." - ), - ARRAY(Integer), - ) - ).label("ancestor_id"), - ] + id.label("id"), + func.unnest( + cast( + func.string_to_array( + func.regexp_replace(path, r"\.?\d+$", ""), "." + ), + ARRAY(Integer), + ) + ).label("ancestor_id"), ).alias() ancestors = relationship( "Node", diff --git a/examples/nested_sets/nested_sets.py b/examples/nested_sets/nested_sets.py index ba45231ce..ca3e91c9a 100644 --- a/examples/nested_sets/nested_sets.py +++ b/examples/nested_sets/nested_sets.py @@ -46,7 +46,7 @@ def before_insert(mapper, connection, instance): else: personnel = mapper.mapped_table right_most_sibling = connection.scalar( - select([personnel.c.rgt]).where( + select(personnel.c.rgt).where( personnel.c.emp == instance.parent.emp ) ) diff --git a/examples/performance/short_selects.py b/examples/performance/short_selects.py index ff9156360..4e5c3eb00 100644 --- a/examples/performance/short_selects.py +++ b/examples/performance/short_selects.py @@ -159,7 +159,7 @@ def test_core_new_stmt_each_time(n): with engine.connect() as conn: for id_ in random.sample(ids, n): - stmt = select([Customer.__table__]).where(Customer.id == id_) + stmt = select(Customer.__table__).where(Customer.id == id_) row = conn.execute(stmt).first() tuple(row) @@ -173,7 +173,7 @@ def test_core_new_stmt_each_time_compiled_cache(n): compiled_cache=compiled_cache ) as conn: for id_ in random.sample(ids, n): - stmt = select([Customer.__table__]).where(Customer.id == id_) + stmt = select(Customer.__table__).where(Customer.id == id_) row = conn.execute(stmt).first() tuple(row) @@ -182,7 +182,7 @@ def test_core_new_stmt_each_time_compiled_cache(n): def test_core_reuse_stmt(n): """test core, reusing the same statement (but recompiling each time).""" - stmt = select([Customer.__table__]).where(Customer.id == bindparam("id")) + stmt = select(Customer.__table__).where(Customer.id == bindparam("id")) with engine.connect() as conn: for id_ in random.sample(ids, n): @@ -194,7 +194,7 @@ def test_core_reuse_stmt(n): def test_core_reuse_stmt_compiled_cache(n): """test core, reusing the same statement + compiled cache.""" - stmt = select([Customer.__table__]).where(Customer.id == bindparam("id")) + stmt = select(Customer.__table__).where(Customer.id == bindparam("id")) compiled_cache = {} with engine.connect().execution_options( compiled_cache=compiled_cache diff --git a/examples/postgis/postgis.py b/examples/postgis/postgis.py index 868d3d055..a12b824ba 100644 --- a/examples/postgis/postgis.py +++ b/examples/postgis/postgis.py @@ -190,13 +190,10 @@ def setup_ddl_events(): for c in gis_cols: bind.execute( select( - [ - func.DropGeometryColumn( - "public", table.name, c.name - ) - ], - autocommit=True, - ) + func.DropGeometryColumn( + "public", table.name, c.name + ) + ).execution_options(autocommit=True) ) elif event == "after-create": @@ -205,17 +202,14 @@ def setup_ddl_events(): if isinstance(c.type, Geometry): bind.execute( select( - [ - func.AddGeometryColumn( - table.name, - c.name, - c.type.srid, - c.type.name, - c.type.dimension, - ) - ], - autocommit=True, - ) + func.AddGeometryColumn( + table.name, + c.name, + c.type.srid, + c.type.name, + c.type.dimension, + ) + ).execution_options(autocommit=True) ) elif event == "after-drop": table.columns = table.info.pop("_saved_columns") @@ -319,7 +313,7 @@ if __name__ == "__main__": # core usage just fine: road_table = Road.__table__ - stmt = select([road_table]).where( + stmt = select(road_table).where( road_table.c.road_geom.intersects(r1.road_geom) ) print(session.execute(stmt).fetchall()) @@ -329,7 +323,7 @@ if __name__ == "__main__": # look up the hex binary version, using SQLAlchemy casts as_binary = session.scalar( - select([type_coerce(r.road_geom, Geometry(coerce_="binary"))]) + select(type_coerce(r.road_geom, Geometry(coerce_="binary"))) ) assert as_binary.as_hex == ( "01020000000200000000000000b832084100000000" @@ -338,7 +332,7 @@ if __name__ == "__main__": # back again, same method ! as_text = session.scalar( - select([type_coerce(as_binary, Geometry(coerce_="text"))]) + select(type_coerce(as_binary, Geometry(coerce_="text"))) ) assert as_text.desc == "LINESTRING(198231 263418,198213 268322)" diff --git a/examples/versioned_history/test_versioning.py b/examples/versioned_history/test_versioning.py index 71a6b6ad2..6c7d05f9a 100644 --- a/examples/versioned_history/test_versioning.py +++ b/examples/versioned_history/test_versioning.py @@ -460,10 +460,10 @@ class TestVersioning(TestCase, AssertsCompiledSQL): sess.commit() actual_changed_base = sess.scalar( - select([BaseClass.__history_mapper__.local_table.c.changed]) + select(BaseClass.__history_mapper__.local_table.c.changed) ) actual_changed_sub = sess.scalar( - select([SubClass.__history_mapper__.local_table.c.changed]) + select(SubClass.__history_mapper__.local_table.c.changed) ) h1 = sess.query(BaseClassHistory).first() eq_(h1.changed, actual_changed_base) diff --git a/examples/versioned_rows/versioned_rows_w_versionid.py b/examples/versioned_rows/versioned_rows_w_versionid.py index 4861fb366..7a1fe5419 100644 --- a/examples/versioned_rows/versioned_rows_w_versionid.py +++ b/examples/versioned_rows/versioned_rows_w_versionid.py @@ -39,7 +39,7 @@ class Versioned(object): def __declare_last__(cls): alias = cls.__table__.alias() cls.calc_is_current_version = column_property( - select([func.max(alias.c.version_id) == cls.version_id]).where( + select(func.max(alias.c.version_id) == cls.version_id).where( alias.c.id == cls.id ) ) |
