summaryrefslogtreecommitdiff
path: root/alembic/ddl/impl.py
diff options
context:
space:
mode:
Diffstat (limited to 'alembic/ddl/impl.py')
-rw-r--r--alembic/ddl/impl.py75
1 files changed, 9 insertions, 66 deletions
diff --git a/alembic/ddl/impl.py b/alembic/ddl/impl.py
index 3cca1ef..debef26 100644
--- a/alembic/ddl/impl.py
+++ b/alembic/ddl/impl.py
@@ -1,17 +1,13 @@
-from sqlalchemy.sql.expression import _BindParamClause
-from sqlalchemy.ext.compiler import compiles
-from sqlalchemy import schema, text, sql
+from sqlalchemy import schema, text
from sqlalchemy import types as sqltypes
-from ..compat import string_types, text_type, with_metaclass
+from ..util.compat import (
+ string_types, text_type, with_metaclass
+)
+from ..util import sqla_compat
from .. import util
from . import base
-if util.sqla_08:
- from sqlalchemy.sql.expression import TextClause
-else:
- from sqlalchemy.sql.expression import _TextClause as TextClause
-
class ImplMeta(type):
@@ -221,8 +217,10 @@ class DefaultImpl(with_metaclass(ImplMeta)):
for row in rows:
self._exec(table.insert(inline=True).values(**dict(
(k,
- _literal_bindparam(k, v, type_=table.c[k].type)
- if not isinstance(v, _literal_bindparam) else v)
+ sqla_compat._literal_bindparam(
+ k, v, type_=table.c[k].type)
+ if not isinstance(
+ v, sqla_compat._literal_bindparam) else v)
for k, v in row.items()
)))
else:
@@ -320,61 +318,6 @@ class DefaultImpl(with_metaclass(ImplMeta)):
self.static_output("COMMIT" + self.command_terminator)
-class _literal_bindparam(_BindParamClause):
- pass
-
-
-@compiles(_literal_bindparam)
-def _render_literal_bindparam(element, compiler, **kw):
- return compiler.render_literal_bindparam(element, **kw)
-
-
-def _textual_index_column(table, text_):
- """a workaround for the Index construct's severe lack of flexibility"""
- if isinstance(text_, string_types):
- c = schema.Column(text_, sqltypes.NULLTYPE)
- table.append_column(c)
- return c
- elif isinstance(text_, TextClause):
- return _textual_index_element(table, text_)
- else:
- raise ValueError("String or text() construct expected")
-
-
-class _textual_index_element(sql.ColumnElement):
- """Wrap around a sqlalchemy text() construct in such a way that
- we appear like a column-oriented SQL expression to an Index
- construct.
-
- The issue here is that currently the Postgresql dialect, the biggest
- recipient of functional indexes, keys all the index expressions to
- the corresponding column expressions when rendering CREATE INDEX,
- so the Index we create here needs to have a .columns collection that
- is the same length as the .expressions collection. Ultimately
- SQLAlchemy should support text() expressions in indexes.
-
- See https://bitbucket.org/zzzeek/sqlalchemy/issue/3174/\
- support-text-sent-to-indexes
-
- """
- __visit_name__ = '_textual_idx_element'
-
- def __init__(self, table, text):
- self.table = table
- self.text = text
- self.key = text.text
- self.fake_column = schema.Column(self.text.text, sqltypes.NULLTYPE)
- table.append_column(self.fake_column)
-
- def get_children(self):
- return [self.fake_column]
-
-
-@compiles(_textual_index_element)
-def _render_textual_index_column(element, compiler, **kw):
- return compiler.process(element.text, **kw)
-
-
def _string_compare(t1, t2):
return \
t1.length is not None and \