本文整理汇总了Python中sqlalchemy.sql.column方法的典型用法代码示例。如果您正苦于以下问题:Python sql.column方法的具体用法?Python sql.column怎么用?Python sql.column使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.sql
的用法示例。
在下文中一共展示了sql.column方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: downgrade
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def downgrade():
''' Remove column access_id from user_projects and projects_groups '''
# this removes the current constraints as well.
op.drop_column('user_projects', 'access')
op.drop_column('projects_groups', 'access')
# recreate the previous constraints
op.create_unique_constraint(
None,
'user_projects',
['project_id', 'user_id'],
)
op.create_primary_key(
None,
'projects_groups',
['project_id', 'group_id'],
)
op.drop_table('access_levels')
示例2: columns
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def columns(self):
"""The set of columns exported by this :class:`.FunctionElement`.
Function objects currently have no result column names built in;
this method returns a single-element column collection with
an anonymously named column.
An interim approach to providing named columns for a function
as a FROM clause is to build a :func:`.select` with the
desired columns::
from sqlalchemy.sql import column
stmt = select([column('x'), column('y')]).\
select_from(func.myfunction())
"""
return ColumnCollection(self.label(None))
示例3: _clone
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def _clone(self):
"""Create a shallow copy of this ClauseElement.
This method may be used by a generative API. Its also used as
part of the "deep" copy afforded by a traversal that combines
the _copy_internals() method.
"""
c = self.__class__.__new__(self.__class__)
c.__dict__ = self.__dict__.copy()
ClauseElement._cloned_set._reset(c)
ColumnElement.comparator._reset(c)
# this is a marker that helps to "equate" clauses to each other
# when a Select returns its list of FROM clauses. the cloning
# process leaves around a lot of remnants of the previous clause
# typically in the form of column expressions still attached to the
# old table.
c._is_clone_of = self
return c
示例4: _find_columns
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def _find_columns(clause):
"""locate Column objects within the given expression."""
cols = util.column_set()
traverse(clause, {}, {'column': cols.add})
return cols
# there is some inconsistency here between the usage of
# inspect() vs. checking for Visitable and __clause_element__.
# Ideally all functions here would derive from inspect(),
# however the inspect() versions add significant callcount
# overhead for critical functions like _interpret_as_column_or_from().
# Generally, the column-based functions are more performance critical
# and are fine just checking for __clause_element__(). It is only
# _interpret_as_from() where we'd like to be able to receive ORM entities
# that have no defined namespace, hence inspect() is needed there.
示例5: dimensions
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def dimensions(self):
_dimensions = []
for dim in self.model_desc.get('simplified_dimensions'):
table_alias = dim.get('column').split('.')[0]
table = dict(self._model_lookups).get(table_alias)
table = table.get('table') if table else self.fact_table.fullname
table_clz = _Table(table, table_alias)
column = dim['column'].split('.')[1]
column_alias = dim['name']
tbl_map = self.tables_and_columns
description = dict(tbl_map[table_clz.fullname].get('columns')).get(column)
if description:
ke4_dim_id = dim.get('id')
ke4_dim_status = dim.get('status')
column_clz = _Column(column, column_alias, description)
_dimensions.append(_CubeDimension(table_clz, column_clz, ke4_dim_id, ke4_dim_status))
return _dimensions
示例6: dimensions
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def dimensions(self):
_dimensions = []
for dim in self.cube_desc.get('dimensions'):
table_alias = dim.get('table')
table = dict(self._model_lookups).get(table_alias)
table = table.get('table') if table else self.fact_table.fullname
table_clz = _Table(table, table_alias)
column = dim['column'] if dim['derived'] is None else dim['derived'][0]
column_alias = dim['name']
tbl_map = self.tables_and_columns
description = dict(tbl_map[table_clz.fullname].get('columns')).get(column)
column_clz = _Column(column, column_alias, description)
_dimensions.append(_CubeDimension(table_clz, column_clz))
return _dimensions
示例7: upgrade
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def upgrade():
# Add collumn redirect_prefix
op.add_column(
u'l7policy',
sa.Column(u'redirect_prefix', sa.String(255), nullable=True)
)
insert_table = sql.table(
u'l7policy_action',
sql.column(u'name', sa.String),
sql.column(u'description', sa.String)
)
op.bulk_insert(
insert_table,
[
{'name': 'REDIRECT_PREFIX'}
]
)
示例8: batch_add_column
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def batch_add_column(
cls, operations, column, insert_before=None, insert_after=None
):
"""Issue an "add column" instruction using the current
batch migration context.
.. seealso::
:meth:`.Operations.add_column`
"""
kw = {}
if insert_before:
kw["insert_before"] = insert_before
if insert_after:
kw["insert_after"] = insert_after
op = cls(
operations.impl.table_name,
column,
schema=operations.impl.schema,
**kw
)
return operations.invoke(op)
示例9: batch_drop_column
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def batch_drop_column(cls, operations, column_name, **kw):
"""Issue a "drop column" instruction using the current
batch migration context.
.. seealso::
:meth:`.Operations.drop_column`
"""
op = cls(
operations.impl.table_name,
column_name,
schema=operations.impl.schema,
**kw
)
return operations.invoke(op)
示例10: alias
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def alias(self, name=None, flat=False):
"""Produce a :class:`.Alias` construct against this
:class:`.FunctionElement`.
This construct wraps the function in a named alias which
is suitable for the FROM clause, in the style accepted for example
by Postgresql.
e.g.::
from sqlalchemy.sql import column
stmt = select([column('data_view')]).\\
select_from(SomeTable).\\
select_from(func.unnest(SomeTable.data).alias('data_view')
)
Would produce:
.. sourcecode:: sql
SELECT data_view
FROM sometable, unnest(sometable.data) AS data_view
.. versionadded:: 0.9.8 The :meth:`.FunctionElement.alias` method
is now supported. Previously, this method's behavior was
undefined and did not behave consistently across versions.
"""
return Alias(self, name)
示例11: expression
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def expression(self):
"""Return a column expression.
Part of the inspection interface; returns self.
"""
return self
示例12: _compare_name_for_result
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def _compare_name_for_result(self, other):
"""Return True if the given column element compares to this one
when targeting within a result row."""
return hasattr(other, 'name') and hasattr(self, 'name') and \
other.name == self.name
示例13: compare
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def compare(self, other, use_proxies=False, equivalents=None, **kw):
"""Compare this ColumnElement to another.
Special arguments understood:
:param use_proxies: when True, consider two columns that
share a common base column as equivalent (i.e. shares_lineage())
:param equivalents: a dictionary of columns as keys mapped to sets
of columns. If the given "other" column is present in this
dictionary, if any of the columns in the corresponding set() pass
the comparison test, the result is True. This is used to expand the
comparison to other columns that may be known to be equivalent to
this one via foreign key or other criterion.
"""
to_compare = (other, )
if equivalents and other in equivalents:
to_compare = equivalents[other].union(to_compare)
for oth in to_compare:
if use_proxies and self.shares_lineage(oth):
return True
elif hash(oth) == hash(self):
return True
else:
return False
示例14: label
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def label(self, name):
"""Produce a column label, i.e. ``<columnname> AS <name>``.
This is a shortcut to the :func:`~.expression.label` function.
if 'name' is None, an anonymous label name will be generated.
"""
return Label(name, self, self.type)
示例15: literal_column
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import column [as 别名]
def literal_column(text, type_=None):
"""Produce a :class:`.ColumnClause` object that has the
:paramref:`.column.is_literal` flag set to True.
:func:`.literal_column` is similar to :func:`.column`, except that
it is more often used as a "standalone" column expression that renders
exactly as stated; while :func:`.column` stores a string name that
will be assumed to be part of a table and may be quoted as such,
:func:`.literal_column` can be that, or any other arbitrary column-oriented
expression.
:param text: the text of the expression; can be any SQL expression.
Quoting rules will not be applied. To specify a column-name expression
which should be subject to quoting rules, use the :func:`column`
function.
:param type\_: an optional :class:`~sqlalchemy.types.TypeEngine`
object which will
provide result-set translation and additional expression semantics for
this column. If left as None the type will be NullType.
.. seealso::
:func:`.column`
:func:`.text`
:ref:`sqlexpression_literal_column`
"""
return ColumnClause(text, type_=type_, is_literal=True)