本文整理汇总了Python中sqlalchemy.sql.table方法的典型用法代码示例。如果您正苦于以下问题:Python sql.table方法的具体用法?Python sql.table怎么用?Python sql.table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.sql
的用法示例。
在下文中一共展示了sql.table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _clone
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql 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: dimensions
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import table [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
示例3: dimensions
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import table [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
示例4: upgrade
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import table [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'}
]
)
示例5: upgrade
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import table [as 别名]
def upgrade():
# re-size existing data if necessary
identifier_map = table('cisco_csr_identifier_map',
column('ipsec_site_conn_id', sa.String(36)))
ipsec_site_conn_id = identifier_map.columns['ipsec_site_conn_id']
op.execute(identifier_map.update(values={
ipsec_site_conn_id: expr.case([(func.length(ipsec_site_conn_id) > 36,
func.substr(ipsec_site_conn_id, 1, 36))],
else_=ipsec_site_conn_id)}))
# Need to drop foreign key constraint before mysql will allow changes
with migration.remove_fks_from_table('cisco_csr_identifier_map'):
op.alter_column(table_name='cisco_csr_identifier_map',
column_name='ipsec_site_conn_id',
type_=sa.String(36),
existing_nullable=False)
示例6: test_bulk_insert_inline_literal_as_sql
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import table [as 别名]
def test_bulk_insert_inline_literal_as_sql(self):
context = op_fixture("postgresql", True)
class MyType(TypeEngine):
pass
t1 = table("t", column("id", Integer), column("data", MyType()))
op.bulk_insert(
t1,
[
{"id": 1, "data": op.inline_literal("d1")},
{"id": 2, "data": op.inline_literal("d2")},
],
)
context.assert_(
"INSERT INTO t (id, data) VALUES (1, 'd1')",
"INSERT INTO t (id, data) VALUES (2, 'd2')",
)
示例7: test_bulk_insert_as_sql_mssql
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import table [as 别名]
def test_bulk_insert_as_sql_mssql(self):
context = self._test_bulk_insert("mssql", True)
# SQL server requires IDENTITY_INSERT
# TODO: figure out if this is safe to enable for a table that
# doesn't have an IDENTITY column
context.assert_(
"SET IDENTITY_INSERT ins_table ON",
"GO",
"INSERT INTO ins_table (id, v1, v2) "
"VALUES (1, 'row v1', 'row v5')",
"GO",
"INSERT INTO ins_table (id, v1, v2) "
"VALUES (2, 'row v2', 'row v6')",
"GO",
"INSERT INTO ins_table (id, v1, v2) "
"VALUES (3, 'row v3', 'row v7')",
"GO",
"INSERT INTO ins_table (id, v1, v2) "
"VALUES (4, 'row v4', 'row v8')",
"GO",
"SET IDENTITY_INSERT ins_table OFF",
"GO",
)
示例8: setUp
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import table [as 别名]
def setUp(self):
self.conn = config.db.connect()
self.conn.execute(
text(
"""
create table foo(
id integer primary key,
data varchar(50),
x integer
)
"""
)
)
context = MigrationContext.configure(self.conn)
self.op = op.Operations(context)
self.t1 = table("foo", column("id"), column("data"), column("x"))
示例9: test_bulk_insert_inline_literal
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import table [as 别名]
def test_bulk_insert_inline_literal(self):
class MyType(TypeEngine):
pass
t1 = table("foo", column("id", Integer), column("data", MyType()))
self.op.bulk_insert(
t1,
[
{"id": 1, "data": self.op.inline_literal("d1")},
{"id": 2, "data": self.op.inline_literal("d2")},
],
multiinsert=False,
)
eq_(
self.conn.execute(text("select id, data from foo")).fetchall(),
[(1, "d1"), (2, "d2")],
)
示例10: setup_class
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import table [as 别名]
def setup_class(cls):
cls.bind = config.db
with config.db.connect() as conn:
conn.execute(
text(
"""
create table tab (
col varchar(50)
)
"""
)
)
conn.execute(
text(
"""
insert into tab (col) values
('old data 1'),
('old data 2.1'),
('old data 3')
"""
)
)
示例11: test_render_table_w_unsupported_constraint
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import table [as 别名]
def test_render_table_w_unsupported_constraint(self):
from sqlalchemy.sql.schema import ColumnCollectionConstraint
class SomeCustomConstraint(ColumnCollectionConstraint):
__visit_name__ = "some_custom"
m = MetaData()
t = Table("t", m, Column("id", Integer), SomeCustomConstraint("id"))
op_obj = ops.CreateTableOp.from_table(t)
with assertions.expect_warnings(
"No renderer is established for object SomeCustomConstraint"
):
eq_ignore_whitespace(
autogenerate.render_op_text(self.autogen_context, op_obj),
"op.create_table('t',"
"sa.Column('id', sa.Integer(), nullable=True),"
"[Unknown Python object "
"SomeCustomConstraint(Column('id', Integer(), table=<t>))])",
)
示例12: setUp
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import table [as 别名]
def setUp(self):
convention = {
"ix": "ix_%(custom)s_%(column_0_label)s",
"uq": "uq_%(custom)s_%(table_name)s_%(column_0_name)s",
"ck": "ck_%(custom)s_%(table_name)s",
"fk": "fk_%(custom)s_%(table_name)s_"
"%(column_0_name)s_%(referred_table_name)s",
"pk": "pk_%(custom)s_%(table_name)s",
"custom": lambda const, table: "ct",
}
self.metadata = MetaData(naming_convention=convention)
ctx_opts = {
"sqlalchemy_module_prefix": "sa.",
"alembic_module_prefix": "op.",
"target_metadata": MetaData(),
}
context = MigrationContext.configure(
dialect_name="postgresql", opts=ctx_opts
)
self.autogen_context = api.AutogenContext(context)
示例13: upgrade
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import table [as 别名]
def upgrade():
relative_modifier = table('relative_modifier',
column('id', sa.Integer),
column('value', sa.Float),
column('numeric_value', sa.Numeric(precision=8, scale=5)))
op.add_column('relative_modifier',
sa.Column('numeric_value', sa.Numeric(precision=8, scale=5)))
conn = op.get_bind()
sel = select([relative_modifier.c.id, relative_modifier.c.value])
results = conn.execute(sel)
q = Decimal(10) ** -5
for id_, float_value in results:
decimal_value = Decimal(float_value).quantize(q)
up = update(relative_modifier).where(relative_modifier.c.id == id_)\
.values({'numeric_value': decimal_value})
conn.execute(up)
op.drop_column('relative_modifier', 'value')
op.alter_column('relative_modifier', 'numeric_value', nullable=True,
new_column_name='value', existing_type=sa.Numeric(precision=8,
scale=5))
示例14: api_private_runs_by_month
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import table [as 别名]
def api_private_runs_by_month():
# The query takes ~6s on local SSD @ AMS on 2018-04-04.
# It was taking ~20s when it was fetching all the table from DB and doing grouping locally.
# TODO: use-count-table
# FIXME: support fastpath
now = datetime.now()
end_date = datetime(now.year, now.month, 1)
start_date = end_date - relativedelta(months=24)
rawsql = """SELECT
date_trunc('month', report.test_start_time) AS test_start_month,
count(*) AS count_1
FROM report
WHERE report.test_start_time >= :start_date
AND report.test_start_time < :end_date
GROUP BY test_start_month
"""
params = dict(start_date=start_date, end_date=end_date)
q = current_app.db_session.execute(rawsql, params)
delta = relativedelta(months=+1, days=-1)
result = [
{"date": (bkt + delta).strftime("%Y-%m-%d"), "value": value}
for bkt, value in sorted(q.fetchall())
]
return jsonify(result)
示例15: __init__
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql 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)