summaryrefslogtreecommitdiff
path: root/alembic/environment.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-04-07 12:36:51 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-04-07 12:41:46 -0400
commit0e1c0989894f13b29a00c9504b887568a40d6648 (patch)
treee05ebe211e0c5f227840d1a2895288b77c62cbc0 /alembic/environment.py
parent54e4f58d1f5315a6bb4c579d1ac8cdb802e7439e (diff)
downloadalembic-0e1c0989894f13b29a00c9504b887568a40d6648.tar.gz
- Added a new option
:paramref:`.EnvironmentContext.configure.literal_binds`, which will pass the ``literal_binds`` flag into the compilation of SQL constructs when using "offline" mode. This has the effect that SQL objects like inserts, updates, deletes as well as textual statements sent using ``text()`` will be compiled such that the dialect will attempt to render literal values "inline" automatically. Only a subset of types is typically supported; the :meth:`.Operations.inline_literal` construct remains as the construct used to force a specific literal representation of a value. The :paramref:`.EnvironmentContext.configure.literal_binds` flag is added to the "offline" section of the ``env.py`` files generated in new environments. fixes #255 - enhance the op_fixture as well as MigrationContext._stdout_connection() so that it uses the real DefaultImpl and MigrationContext fully in tests.
Diffstat (limited to 'alembic/environment.py')
-rw-r--r--alembic/environment.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/alembic/environment.py b/alembic/environment.py
index 45983d1..130a50f 100644
--- a/alembic/environment.py
+++ b/alembic/environment.py
@@ -296,6 +296,7 @@ class EnvironmentContext(object):
compare_type=False,
compare_server_default=False,
render_item=None,
+ literal_binds=False,
upgrade_token="upgrades",
downgrade_token="downgrades",
alembic_module_prefix="op.",
@@ -365,6 +366,24 @@ class EnvironmentContext(object):
object.
:param output_encoding: when using ``--sql`` to generate SQL
scripts, apply this encoding to the string output.
+ :param literal_binds: when using ``--sql`` to generate SQL
+ scripts, pass through the ``literal_binds`` flag to the compiler
+ so that any literal values that would ordinarily be bound
+ parameters are converted to plain strings.
+
+ .. warning:: Dialects can typically only handle simple datatypes
+ like strings and numbers for auto-literal generation. Datatypes
+ like dates, intervals, and others may still require manual
+ formatting, typically using :meth:`.Operations.inline_literal`.
+
+ .. note:: the ``literal_binds`` flag is ignored on SQLAlchemy
+ versions prior to 0.8 where this feature is not supported.
+
+ .. versionadded:: 0.7.6
+
+ .. seealso::
+
+ :meth:`.Operations.inline_literal`
:param starting_rev: Override the "starting revision" argument
when using ``--sql`` mode.
@@ -700,6 +719,7 @@ class EnvironmentContext(object):
opts['sqlalchemy_module_prefix'] = sqlalchemy_module_prefix
opts['alembic_module_prefix'] = alembic_module_prefix
opts['user_module_prefix'] = user_module_prefix
+ opts['literal_binds'] = literal_binds
if render_item is not None:
opts['render_item'] = render_item
if compare_type is not None: