本文整理汇总了Python中sqlalchemy.table方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.table方法的具体用法?Python sqlalchemy.table怎么用?Python sqlalchemy.table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _clone
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [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
示例2: migrate_pools
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [as 别名]
def migrate_pools():
conn = op.get_bind()
lb_table = sa.sql.table(
'load_balancer',
sa.sql.column('id', sa.String),
sa.sql.column('provider', sa.String),
sa.sql.column('provisioning_status', sa.String))
pool_table = sa.sql.table(
'pool',
sa.sql.column('id', sa.String),
sa.sql.column('load_balancer_id', sa.String),
sa.sql.column('lb_algorithm', sa.String))
j = pool_table.join(lb_table,
pool_table.c.load_balancer_id == lb_table.c.id)
stmt = sa.select([pool_table.c.id]).select_from(j).where(
lb_table.c.provider == 'ovn')
result = conn.execute(stmt)
for row in result:
stmt = pool_table.update().values(lb_algorithm='SOURCE_IP_PORT').where(
pool_table.c.id == row[0])
op.execute(stmt)
示例3: schema_from_table
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [as 别名]
def schema_from_table(table, schema=None):
"""Retrieve an ibis schema from a SQLAlchemy ``Table``.
Parameters
----------
table : sa.Table
Returns
-------
schema : ibis.expr.datatypes.Schema
An ibis schema corresponding to the types of the columns in `table`.
"""
schema = schema if schema is not None else {}
pairs = []
for name, column in table.columns.items():
if name in schema:
dtype = dt.dtype(schema[name])
else:
dtype = dt.dtype(
getattr(table.bind, 'dialect', SQLAlchemyDialect()),
column.type,
nullable=column.nullable,
)
pairs.append((name, dtype))
return sch.schema(pairs)
示例4: invalidates_reflection_cache
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [as 别名]
def invalidates_reflection_cache(f):
"""Invalidate the SQLAlchemy reflection cache if `f` performs an operation
that mutates database or table metadata such as ``CREATE TABLE``,
``DROP TABLE``, etc.
Parameters
----------
f : callable
A method on :class:`ibis.sql.alchemy.AlchemyClient`
"""
@functools.wraps(f)
def wrapped(self, *args, **kwargs):
result = f(self, *args, **kwargs)
# only invalidate the cache after we've succesfully called the wrapped
# function
self._reflection_cache_is_dirty = True
return result
return wrapped
示例5: _can_lower_sort_column
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [as 别名]
def _can_lower_sort_column(table_set, expr):
# TODO(wesm): This code is pending removal through cleaner internal
# semantics
# we can currently sort by just-appeared aggregate metrics, but the way
# these are references in the expression DSL is as a SortBy (blocking
# table operation) on an aggregation. There's a hack in _collect_SortBy
# in the generic SQL compiler that "fuses" the sort with the
# aggregation so they appear in same query. It's generally for
# cosmetics and doesn't really affect query semantics.
bases = ops.find_all_base_tables(expr)
if len(bases) > 1:
return False
base = list(bases.values())[0]
base_op = base.op()
if isinstance(base_op, ops.Aggregation):
return base_op.table.equals(table_set)
elif isinstance(base_op, ops.Selection):
return base.equals(table_set)
else:
return False
示例6: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [as 别名]
def upgrade():
### commands auto generated by Alembic - please adjust! ###
role_table = sa.table('role',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('name', sa.String(length=80), nullable=False),
sa.Column('description', sa.String(length=255), nullable=True),
sa.Column('parent_id', sa.Integer(), nullable=True),
)
res = op.get_bind().execute('SELECT max(id)+1 FROM role')
cm = 46
for r in res.fetchall():
cm = r[0]
op.bulk_insert(role_table, [
{'id': cm, 'name': 'import_store_data', 'description': u'导入店铺运营数据', 'parent_id': None},
], multiinsert=False)
from sqlalchemy.sql import text
op.get_bind().execute(text("ALTER SEQUENCE role_id_seq RESTART WITH " + str(cm + 1) + ";"))
### end Alembic commands ###
示例7: _clone
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [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.
"""
skip = self._memoized_keys
c = self.__class__.__new__(self.__class__)
c.__dict__ = {k: v for k, v in self.__dict__.items() if k not in skip}
# 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
示例8: __init__
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [as 别名]
def __init__(self, *clauses, **kw):
"""Return a :class:`.Tuple`.
Main usage is to produce a composite IN construct::
from sqlalchemy import tuple_
tuple_(table.c.col1, table.c.col2).in_(
[(1, 2), (5, 12), (10, 19)]
)
.. warning::
The composite IN construct is not supported by all backends,
and is currently known to work on Postgresql and MySQL,
but not SQLite. Unsupported backends will raise
a subclass of :class:`~sqlalchemy.exc.DBAPIError` when such
an expression is invoked.
"""
clauses = [_literal_as_binds(c) for c in clauses]
self._type_tuple = [arg.type for arg in clauses]
self.type = kw.pop('type_', self._type_tuple[0]
if self._type_tuple else type_api.NULLTYPE)
super(Tuple, self).__init__(*clauses, **kw)
示例9: literal_column
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [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)
示例10: _compare_name_for_result
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [as 别名]
def _compare_name_for_result(self, other):
if self.is_literal or \
self.table is None or self.table._textual or \
not hasattr(other, 'proxy_set') or (
isinstance(other, ColumnClause) and
(other.is_literal or
other.table is None or
other.table._textual)
):
return (hasattr(other, 'name') and self.name == other.name) or \
(hasattr(other, '_label') and self._label == other._label)
else:
return other.proxy_set.intersection(self.proxy_set)
示例11: _get_table
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [as 别名]
def _get_table(self):
return self.__dict__['table']
示例12: _from_objects
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [as 别名]
def _from_objects(self):
t = self.table
if t is not None:
return [t]
else:
return []
示例13: _render_label_in_columns_clause
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [as 别名]
def _render_label_in_columns_clause(self):
return self.table is not None
示例14: _gen_label
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [as 别名]
def _gen_label(self, name):
t = self.table
if self.is_literal:
return None
elif t is not None and t.named_with_column:
if getattr(t, 'schema', None):
label = t.schema.replace('.', '_') + "_" + \
t.name + "_" + name
else:
label = t.name + "_" + name
# propagate name quoting rules for labels.
if getattr(name, "quote", None) is not None:
if isinstance(label, quoted_name):
label.quote = name.quote
else:
label = quoted_name(label, name.quote)
elif getattr(t.name, "quote", None) is not None:
# can't get this situation to occur, so let's
# assert false on it for now
assert not isinstance(label, quoted_name)
label = quoted_name(label, t.name.quote)
# ensure the label name doesn't conflict with that
# of an existing column
if label in t.c:
_label = label
counter = 1
while _label in t.c:
_label = label + "_" + str(counter)
counter += 1
label = _label
return _as_truncated(label)
else:
return name
示例15: _corresponding_column_or_error
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import table [as 别名]
def _corresponding_column_or_error(fromclause, column,
require_embedded=False):
c = fromclause.corresponding_column(column,
require_embedded=require_embedded)
if c is None:
raise exc.InvalidRequestError(
"Given column '%s', attached to table '%s', "
"failed to locate a corresponding column from table '%s'"
%
(column,
getattr(column, 'table', None),
fromclause.description)
)
return c