summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/reflection.py
diff options
context:
space:
mode:
authorRoman Podolyaka <roman.podolyaka@gmail.com>2013-06-09 19:07:00 +0300
committerRoman Podolyaka <roman.podolyaka@gmail.com>2013-06-09 23:49:55 +0300
commitc69fe4acf8929856735e5d90adb7f6b6d5ebcd46 (patch)
treee193633bdf96f536d826122a1186d067dbc9890f /lib/sqlalchemy/engine/reflection.py
parentf65ddee93a7143924b417e1c988802f10d0c7b11 (diff)
downloadsqlalchemy-pr/4.tar.gz
Add basic support of unique constraints reflectionpr/4
Inspection API already supports reflection of table indexes information and those also include unique constraints (at least for PostgreSQL and MySQL). But it could be actually useful to distinguish between indexes and plain unique constraints (though both are implemented in the same way internally in RDBMS). This change adds a new method to Inspection API - get_unique_constraints() and implements it for SQLite, PostgreSQL and MySQL dialects.
Diffstat (limited to 'lib/sqlalchemy/engine/reflection.py')
-rw-r--r--lib/sqlalchemy/engine/reflection.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py
index cf2caf679..1926e693a 100644
--- a/lib/sqlalchemy/engine/reflection.py
+++ b/lib/sqlalchemy/engine/reflection.py
@@ -347,6 +347,26 @@ class Inspector(object):
schema,
info_cache=self.info_cache, **kw)
+ def get_unique_constraints(self, table_name, schema=None, **kw):
+ """Return information about unique constraints in `table_name`.
+
+ Given a string `table_name` and an optional string `schema`, return
+ unique constraint information as a list of dicts with these keys:
+
+ name
+ the unique constraint's name
+
+ column_names
+ list of column names in order
+
+ \**kw
+ other options passed to the dialect's get_unique_constraints() method.
+
+ """
+
+ return self.dialect.get_unique_constraints(
+ self.bind, table_name, schema, info_cache=self.info_cache, **kw)
+
def reflecttable(self, table, include_columns, exclude_columns=()):
"""Given a Table object, load its internal constructs based on
introspection.