diff options
author | Tobias Pfeiffer <tgp@preferred.jp> | 2022-11-28 07:52:31 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-11-28 19:47:57 -0500 |
commit | ed39e846cd8ae2714c47fc3d563582f72483df0c (patch) | |
tree | a5c26e979adf3fbd00c34a9ca1f8b63b7423e51c /test/dialect/test_sqlite.py | |
parent | db2344b0a2a9ef164651d645a8da2d7a9d1bc250 (diff) | |
download | sqlalchemy-ed39e846cd8ae2714c47fc3d563582f72483df0c.tar.gz |
add partial index predicate to SQLiteDialect.get_indexes() result
Added support for reflection of expression-oriented WHERE criteria included
in indexes on the SQLite dialect, in a manner similar to that of the
PostgreSQL dialect. Pull request courtesy Tobias Pfeiffer.
Fixes: #8804
Closes: #8806
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8806
Pull-request-sha: 539dfcb372360911b69aed2a804698bb1a2220b1
Change-Id: I0e34d47dbe2b9c1da6fce531363084843e5127a3
Diffstat (limited to 'test/dialect/test_sqlite.py')
-rw-r--r-- | test/dialect/test_sqlite.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index 5bda6577f..d460ef64e 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -2280,6 +2280,7 @@ class ConstraintReflectionTest(fixtures.TestBase): "unique": 1, "name": "sqlite_autoindex_o_1", "column_names": ["foo"], + "dialect_options": {}, } ], ) @@ -2295,10 +2296,60 @@ class ConstraintReflectionTest(fixtures.TestBase): "unique": 0, "name": "ix_main_l_bar", "column_names": ["bar"], + "dialect_options": {}, } ], ) + def test_reflect_partial_indexes(self, connection): + connection.exec_driver_sql( + "create table foo_with_partial_index (x integer, y integer)" + ) + connection.exec_driver_sql( + "create unique index ix_partial on " + "foo_with_partial_index (x) where y > 10" + ) + connection.exec_driver_sql( + "create unique index ix_no_partial on " + "foo_with_partial_index (x)" + ) + connection.exec_driver_sql( + "create unique index ix_partial2 on " + "foo_with_partial_index (x, y) where " + "y = 10 or abs(x) < 5" + ) + + inspector = inspect(connection) + indexes = inspector.get_indexes("foo_with_partial_index") + eq_( + indexes, + [ + { + "unique": 1, + "name": "ix_no_partial", + "column_names": ["x"], + "dialect_options": {}, + }, + { + "unique": 1, + "name": "ix_partial", + "column_names": ["x"], + "dialect_options": {"sqlite_where": mock.ANY}, + }, + { + "unique": 1, + "name": "ix_partial2", + "column_names": ["x", "y"], + "dialect_options": {"sqlite_where": mock.ANY}, + }, + ], + ) + eq_(indexes[1]["dialect_options"]["sqlite_where"].text, "y > 10") + eq_( + indexes[2]["dialect_options"]["sqlite_where"].text, + "y = 10 or abs(x) < 5", + ) + def test_unique_constraint_named(self): inspector = inspect(testing.db) eq_( |