summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/reflection.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/engine/reflection.py')
-rw-r--r--lib/sqlalchemy/engine/reflection.py54
1 files changed, 27 insertions, 27 deletions
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py
index 964e9fbee..cf254cba6 100644
--- a/lib/sqlalchemy/engine/reflection.py
+++ b/lib/sqlalchemy/engine/reflection.py
@@ -55,17 +55,17 @@ class Inspector(object):
:class:`~sqlalchemy.engine.base.Dialect`, providing a
consistent interface as well as caching support for previously
fetched metadata.
-
+
The preferred method to construct an :class:`.Inspector` is via the
:meth:`Inspector.from_engine` method. I.e.::
-
+
engine = create_engine('...')
insp = Inspector.from_engine(engine)
-
+
Where above, the :class:`~sqlalchemy.engine.base.Dialect` may opt
to return an :class:`.Inspector` subclass that provides additional
methods specific to the dialect's target database.
-
+
"""
def __init__(self, bind):
@@ -75,7 +75,7 @@ class Inspector(object):
which is typically an instance of
:class:`~sqlalchemy.engine.base.Engine` or
:class:`~sqlalchemy.engine.base.Connection`.
-
+
For a dialect-specific instance of :class:`.Inspector`, see
:meth:`Inspector.from_engine`
@@ -83,10 +83,10 @@ class Inspector(object):
# ensure initialized
bind.connect()
-
+
# this might not be a connection, it could be an engine.
self.bind = bind
-
+
# set the engine
if hasattr(bind, 'engine'):
self.engine = bind.engine
@@ -103,14 +103,14 @@ class Inspector(object):
which is typically an instance of
:class:`~sqlalchemy.engine.base.Engine` or
:class:`~sqlalchemy.engine.base.Connection`.
-
+
This method differs from direct a direct constructor call of :class:`.Inspector`
in that the :class:`~sqlalchemy.engine.base.Dialect` is given a chance to provide
a dialect-specific :class:`.Inspector` instance, which may provide additional
methods.
-
+
See the example at :class:`.Inspector`.
-
+
"""
if hasattr(bind.dialect, 'inspector'):
return bind.dialect.inspector(bind)
@@ -120,10 +120,10 @@ class Inspector(object):
def default_schema_name(self):
"""Return the default schema name presented by the dialect
for the current engine's database user.
-
+
E.g. this is typically ``public`` for Postgresql and ``dbo``
for SQL Server.
-
+
"""
return self.dialect.default_schema_name
@@ -174,9 +174,9 @@ class Inspector(object):
def get_table_options(self, table_name, schema=None, **kw):
"""Return a dictionary of options specified when the table of the given name was created.
-
+
This currently includes some options that apply to MySQL tables.
-
+
"""
if hasattr(self.dialect, 'get_table_options'):
return self.dialect.get_table_options(self.bind, table_name, schema,
@@ -252,10 +252,10 @@ class Inspector(object):
Given a string `table_name`, and an optional string `schema`, return
primary key information as a dictionary with these keys:
-
+
constrained_columns
a list of column names that make up the primary key
-
+
name
optional name of the primary key constraint.
@@ -265,7 +265,7 @@ class Inspector(object):
**kw)
return pkeys
-
+
def get_foreign_keys(self, table_name, schema=None, **kw):
"""Return information about foreign_keys in `table_name`.
@@ -288,7 +288,7 @@ class Inspector(object):
name
optional name of the foreign key constraint.
-
+
\**kw
other options passed to the dialect's get_foreign_keys() method.
@@ -313,7 +313,7 @@ class Inspector(object):
unique
boolean
-
+
\**kw
other options passed to the dialect's get_indexes() method.
"""
@@ -325,23 +325,23 @@ class Inspector(object):
def reflecttable(self, table, include_columns):
"""Given a Table object, load its internal constructs based on introspection.
-
+
This is the underlying method used by most dialects to produce
table reflection. Direct usage is like::
-
+
from sqlalchemy import create_engine, MetaData, Table
from sqlalchemy.engine import reflection
-
+
engine = create_engine('...')
meta = MetaData()
user_table = Table('user', meta)
insp = Inspector.from_engine(engine)
insp.reflecttable(user_table, None)
-
+
:param table: a :class:`~sqlalchemy.schema.Table` instance.
:param include_columns: a list of string column names to include
in the reflection process. If ``None``, all columns are reflected.
-
+
"""
dialect = self.bind.dialect
@@ -393,13 +393,13 @@ class Inspector(object):
col_kw['autoincrement'] = col_d['autoincrement']
if 'quote' in col_d:
col_kw['quote'] = col_d['quote']
-
+
colargs = []
if col_d.get('default') is not None:
# the "default" value is assumed to be a literal SQL expression,
# so is wrapped in text() so that no quoting occurs on re-issuance.
colargs.append(sa_schema.DefaultClause(sql.text(col_d['default'])))
-
+
if 'sequence' in col_d:
# TODO: mssql, maxdb and sybase are using this.
seq = col_d['sequence']
@@ -409,7 +409,7 @@ class Inspector(object):
if 'increment' in seq:
sequence.increment = seq['increment']
colargs.append(sequence)
-
+
col = sa_schema.Column(name, coltype, *colargs, **col_kw)
table.append_column(col)