]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- consolidate "constraints.py" into the more general "ext.py",
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 27 Aug 2015 14:33:21 +0000 (10:33 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 27 Aug 2015 14:33:21 +0000 (10:33 -0400)
for all assorted PG SQL extensions

lib/sqlalchemy/dialects/postgresql/__init__.py
lib/sqlalchemy/dialects/postgresql/constraints.py [deleted file]
lib/sqlalchemy/dialects/postgresql/ext.py

index 538a2e8007a6df0b6f521647d0bc8e09133e1ba5..2dac6cecc7339ec244e747ca8c4d44b5b9791597 100644 (file)
@@ -14,11 +14,10 @@ from .base import \
     INET, CIDR, UUID, BIT, MACADDR, OID, DOUBLE_PRECISION, TIMESTAMP, TIME, \
     DATE, BYTEA, BOOLEAN, INTERVAL, ENUM, dialect, TSVECTOR, DropEnumType, \
     CreateEnumType
-from .constraints import ExcludeConstraint
 from .hstore import HSTORE, hstore
 from .json import JSON, JSONB
 from .array import array, ARRAY, Any, All
-from .ext import aggregate_order_by
+from .ext import aggregate_order_by, ExcludeConstraint
 
 from .ranges import INT4RANGE, INT8RANGE, NUMRANGE, DATERANGE, TSRANGE, \
     TSTZRANGE
diff --git a/lib/sqlalchemy/dialects/postgresql/constraints.py b/lib/sqlalchemy/dialects/postgresql/constraints.py
deleted file mode 100644 (file)
index 4cfc050..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-# Copyright (C) 2013-2015 the SQLAlchemy authors and contributors
-# <see AUTHORS file>
-#
-# This module is part of SQLAlchemy and is released under
-# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from ...sql.schema import ColumnCollectionConstraint
-from ...sql import expression
-from ... import util
-
-
-class ExcludeConstraint(ColumnCollectionConstraint):
-    """A table-level EXCLUDE constraint.
-
-    Defines an EXCLUDE constraint as described in the `postgres
-    documentation`__.
-
-    __ http://www.postgresql.org/docs/9.0/\
-static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE
-    """
-
-    __visit_name__ = 'exclude_constraint'
-
-    where = None
-
-    def __init__(self, *elements, **kw):
-        """
-        :param \*elements:
-          A sequence of two tuples of the form ``(column, operator)`` where
-          column must be a column name or Column object and operator must
-          be a string containing the operator to use.
-
-        :param name:
-          Optional, the in-database name of this constraint.
-
-        :param deferrable:
-          Optional bool.  If set, emit DEFERRABLE or NOT DEFERRABLE when
-          issuing DDL for this constraint.
-
-        :param initially:
-          Optional string.  If set, emit INITIALLY <value> when issuing DDL
-          for this constraint.
-
-        :param using:
-          Optional string.  If set, emit USING <index_method> when issuing DDL
-          for this constraint. Defaults to 'gist'.
-
-        :param where:
-          Optional string.  If set, emit WHERE <predicate> when issuing DDL
-          for this constraint.
-
-        """
-        columns = []
-        render_exprs = []
-        self.operators = {}
-
-        expressions, operators = zip(*elements)
-
-        for (expr, column, strname, add_element), operator in zip(
-                self._extract_col_expression_collection(expressions),
-                operators
-        ):
-            if add_element is not None:
-                columns.append(add_element)
-
-            name = column.name if column is not None else strname
-
-            if name is not None:
-                # backwards compat
-                self.operators[name] = operator
-
-            expr = expression._literal_as_text(expr)
-
-            render_exprs.append(
-                (expr, name, operator)
-            )
-
-        self._render_exprs = render_exprs
-        ColumnCollectionConstraint.__init__(
-            self,
-            *columns,
-            name=kw.get('name'),
-            deferrable=kw.get('deferrable'),
-            initially=kw.get('initially')
-        )
-        self.using = kw.get('using', 'gist')
-        where = kw.get('where')
-        if where:
-            self.where = expression._literal_as_text(where)
-
-    def copy(self, **kw):
-        elements = [(col, self.operators[col])
-                    for col in self.columns.keys()]
-        c = self.__class__(*elements,
-                           name=self.name,
-                           deferrable=self.deferrable,
-                           initially=self.initially)
-        c.dispatch._update(self.dispatch)
-        return c
index 57592bac2d3fb4f6346451e1c0aaab92fd8b5e2c..8b08cc498680ea6d367fbb732b78750e90d6f0a8 100644 (file)
@@ -7,6 +7,7 @@
 
 from ...sql import expression
 from ...sql import elements
+from ...sql.schema import ColumnCollectionConstraint
 
 
 class aggregate_order_by(expression.ColumnElement):
@@ -61,3 +62,93 @@ class aggregate_order_by(expression.ColumnElement):
     @property
     def _from_objects(self):
         return self.target._from_objects + self.order_by._from_objects
+
+
+class ExcludeConstraint(ColumnCollectionConstraint):
+    """A table-level EXCLUDE constraint.
+
+    Defines an EXCLUDE constraint as described in the `postgres
+    documentation`__.
+
+    __ http://www.postgresql.org/docs/9.0/\
+static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE
+    """
+
+    __visit_name__ = 'exclude_constraint'
+
+    where = None
+
+    def __init__(self, *elements, **kw):
+        """
+        :param \*elements:
+          A sequence of two tuples of the form ``(column, operator)`` where
+          column must be a column name or Column object and operator must
+          be a string containing the operator to use.
+
+        :param name:
+          Optional, the in-database name of this constraint.
+
+        :param deferrable:
+          Optional bool.  If set, emit DEFERRABLE or NOT DEFERRABLE when
+          issuing DDL for this constraint.
+
+        :param initially:
+          Optional string.  If set, emit INITIALLY <value> when issuing DDL
+          for this constraint.
+
+        :param using:
+          Optional string.  If set, emit USING <index_method> when issuing DDL
+          for this constraint. Defaults to 'gist'.
+
+        :param where:
+          Optional string.  If set, emit WHERE <predicate> when issuing DDL
+          for this constraint.
+
+        """
+        columns = []
+        render_exprs = []
+        self.operators = {}
+
+        expressions, operators = zip(*elements)
+
+        for (expr, column, strname, add_element), operator in zip(
+                self._extract_col_expression_collection(expressions),
+                operators
+        ):
+            if add_element is not None:
+                columns.append(add_element)
+
+            name = column.name if column is not None else strname
+
+            if name is not None:
+                # backwards compat
+                self.operators[name] = operator
+
+            expr = expression._literal_as_text(expr)
+
+            render_exprs.append(
+                (expr, name, operator)
+            )
+
+        self._render_exprs = render_exprs
+        ColumnCollectionConstraint.__init__(
+            self,
+            *columns,
+            name=kw.get('name'),
+            deferrable=kw.get('deferrable'),
+            initially=kw.get('initially')
+        )
+        self.using = kw.get('using', 'gist')
+        where = kw.get('where')
+        if where:
+            self.where = expression._literal_as_text(where)
+
+    def copy(self, **kw):
+        elements = [(col, self.operators[col])
+                    for col in self.columns.keys()]
+        c = self.__class__(*elements,
+                           name=self.name,
+                           deferrable=self.deferrable,
+                           initially=self.initially)
+        c.dispatch._update(self.dispatch)
+        return c