From: Ants Aasma Date: Mon, 1 Oct 2007 16:29:26 +0000 (+0000) Subject: Make the postgres_where attribute to Index private to postgres module by using a... X-Git-Tag: rel_0_4_0~86 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fe3178e22457556fc98f577468f0bb24d28ce300;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Make the postgres_where attribute to Index private to postgres module by using a kwargs attribute on the Index. --- diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 76f17bb5bf..9292e6ea49 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -4,6 +4,14 @@ # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php +"""Support for the PostgreSQL database. + +PostgreSQL supports partial indexes. To create them pass a posgres_where +option to the Index constructor:: + + Index('my_index', my_table.c.id, postgres_where=tbl.c.value > 10) +""" + import re, random, warnings, string from sqlalchemy import sql, schema, exceptions, util @@ -622,8 +630,9 @@ class PGSchemaGenerator(compiler.SchemaGenerator): % (preparer.format_index(index), preparer.format_table(index.table), string.join([preparer.format_column(c) for c in index.columns], ', '))) - if index.postgres_where is not None: - compiler = self._compile(index.postgres_where, None) + whereclause = index.kwargs.get('postgres_where', None) + if whereclause is not None: + compiler = self._compile(whereclause, None) # this might belong to the compiler class inlined_clause = str(compiler) % dict((key,bind.value) for key,bind in compiler.binds.iteritems()) self.append(" WHERE " + inlined_clause) diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index fce181cbb8..8ca5567e47 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -956,7 +956,9 @@ class Index(SchemaItem): self.columns = [] self.table = None self.unique = kwargs.pop('unique', False) - self.postgres_where = kwargs.pop('postgres_where', None) + + self.kwargs = kwargs + self._init_items(*columns) def _init_items(self, *args):