diff options
author | Kai Groner <kai@gronr.com> | 2015-01-26 14:49:40 -0500 |
---|---|---|
committer | Kai Groner <kai@gronr.com> | 2015-01-26 14:50:24 -0500 |
commit | 30ce7e93f4068b00ced0db785fdd578dc8a45975 (patch) | |
tree | 173c52b8edca255cdb4482ece8c10933fa4b4f16 | |
parent | 4a42bd5a2cba23782df7b6f98cadb7382d22498e (diff) | |
download | sqlalchemy-30ce7e93f4068b00ced0db785fdd578dc8a45975.tar.gz |
Partial index support with sqlite dialects.
From https://www.sqlite.org/partialindex.html
> Partial indexes have been supported in SQLite since version 3.8.0.
Reflection does not expose the predicate of partial indexes. The
postgresql dialect does detect such indexes and issue a warning. I
looked into matching this level of support, but the sqlite pragma
index_info does not expose the predicate. Getting this data would
probably require parsing the CREATE INDEX statement from sqlite_master.
-rw-r--r-- | lib/sqlalchemy/dialects/sqlite/base.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 1ed89bacb..437a7794a 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -714,9 +714,20 @@ class SQLiteDDLCompiler(compiler.DDLCompiler): return preparer.format_table(table, use_schema=False) def visit_create_index(self, create): - return super(SQLiteDDLCompiler, self).visit_create_index( + index = create.element + + text = super(SQLiteDDLCompiler, self).visit_create_index( create, include_table_schema=False) + whereclause = index.dialect_options["sqlite"]["where"] + if whereclause is not None: + where_compiled = self.sql_compiler.process( + whereclause, include_table=False, + literal_binds=True) + text += " WHERE " + where_compiled + + return text + class SQLiteTypeCompiler(compiler.GenericTypeCompiler): def visit_large_binary(self, type_, **kw): @@ -823,7 +834,10 @@ class SQLiteDialect(default.DefaultDialect): construct_arguments = [ (sa_schema.Table, { "autoincrement": False - }) + }), + (sa_schema.Index, { + "where": None, + }), ] _broken_fk_pragma_quotes = False |