本文整理汇总了Python中sqlalchemy.sql.update方法的典型用法代码示例。如果您正苦于以下问题:Python sql.update方法的具体用法?Python sql.update怎么用?Python sql.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.sql
的用法示例。
在下文中一共展示了sql.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_schedule
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def from_schedule(cls, session, schedule):
spec = {
'minute': schedule._orig_minute,
'hour': schedule._orig_hour,
'day_of_week': schedule._orig_day_of_week,
'day_of_month': schedule._orig_day_of_month,
'month_of_year': schedule._orig_month_of_year,
}
if schedule.tz:
spec.update({
'timezone': schedule.tz.zone
})
model = session.query(CrontabSchedule).filter_by(**spec).first()
if not model:
model = cls(**spec)
session.add(model)
session.commit()
return model
示例2: upgrade
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [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))
示例3: downgrade
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def downgrade():
relative_modifier = table('relative_modifier',
column('id', sa.Integer),
column('value', sa.Numeric(precision=8, scale=5)),
column('float_value', sa.Float))
op.add_column('relative_modifier', sa.Column('float_value', sa.Float))
conn = op.get_bind()
sel = select([relative_modifier.c.id, relative_modifier.c.value])
results = conn.execute(sel)
for id_, decimal_value in results:
float_value = float(decimal_value)
up = update(relative_modifier).where(relative_modifier.c.id == id_)\
.values({'float_value': float_value})
conn.execute(up)
op.drop_column('relative_modifier', 'value')
op.alter_column('relative_modifier', 'float_value', nullable=True,
new_column_name='value', existing_type=sa.Float)
示例4: _pk_strategy_refetch
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def _pk_strategy_refetch(query, mapper, values, surrogate_key):
surrogate_key_name, surrogate_key_value = surrogate_key
surrogate_key_col = mapper.attrs[surrogate_key_name].expression
rowcount = query.\
filter(surrogate_key_col == surrogate_key_value).\
update(values, synchronize_session=False)
_assert_single_row(rowcount)
# SELECT my_table.id AS my_table_id FROM my_table
# WHERE my_table.y = ? AND my_table.z = ?
# LIMIT ? OFFSET ?
fetch_query = query.session.query(
*mapper.primary_key).filter(
surrogate_key_col == surrogate_key_value)
primary_key = fetch_query.one()
return primary_key
示例5: update
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def update(self, **kw):
for attr, value in kw.items():
setattr(self, attr, value)
return self
示例6: update_changed
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def update_changed(cls, mapper, connection, target):
"""
:param mapper: the Mapper which is the target of this event
:param connection: the Connection being used
:param target: the mapped instance being persisted
"""
s = connection.execute(select([PeriodicTaskChanged]).
where(PeriodicTaskChanged.id == 1).limit(1))
if not s:
s = connection.execute(insert(PeriodicTaskChanged),
last_update=dt.datetime.now())
else:
s = connection.execute(update(PeriodicTaskChanged).
where(PeriodicTaskChanged.id == 1).
values(last_update=dt.datetime.now()))
示例7: upgrade
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def upgrade():
op.add_column('request',
sa.Column('numeric_base_payout', sa.Numeric(precision=15, scale=2),
default=0.0)
)
request = table('request',
column('id', sa.Integer),
column('base_payout', sa.Float),
column('numeric_base_payout', sa.Numeric(precision=15, scale=2)),
)
conn = op.get_bind()
requests_sel = select([request.c.id, request.c.base_payout])
requests = conn.execute(requests_sel)
for request_id, float_payout in requests:
decimal_payout = Decimal.from_float(float_payout)
decimal_payout *= 1000000
update_stmt = update(request)\
.where(request.c.id == request_id)\
.values({
'numeric_base_payout': decimal_payout,
})
conn.execute(update_stmt)
requests.close()
op.drop_column('request', 'base_payout')
op.alter_column('request',
column_name='numeric_base_payout',
new_column_name='base_payout',
existing_type=sa.Numeric(precision=15, scale=2),
existing_server_default=0.0)
示例8: downgrade
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def downgrade():
op.add_column('request',
sa.Column('float_base_payout', sa.Float, default=0.0)
)
request = table('request',
column('id', sa.Integer),
column('base_payout', sa.Numeric(precision=15, scale=2)),
column('float_base_payout', sa.Float),
)
conn = op.get_bind()
requests_sel = select([request.c.id, request.c.base_payout])
requests = conn.execute(requests_sel)
for request_id, decimal_payout in requests:
decimal_payout = decimal_payout / 1000000
float_payout = float(decimal_payout)
update_stmt = update(request)\
.where(request.c.id == request_id)\
.values({
'float_base_payout': float_payout,
})
conn.execute(update_stmt)
requests.close()
op.drop_column('request', 'base_payout')
op.alter_column('request',
column_name='numeric_base_payout',
new_column_name='base_payout',
existing_type=sa.Float,
existing_server_default=0.0)
示例9: upgrade
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def upgrade():
conn = op.get_bind()
negative_base_payout_id_sel = select([request.c.id])\
.where(request.c.base_payout < 0.0)
negative_ids = conn.execute(negative_base_payout_id_sel)
for result_row in negative_ids:
negative_id = result_row[0]
update_stmt = update(request)\
.where(request.c.id == negative_id)\
.values({
'base_payout': 0.0,
})
conn.execute(update_stmt)
negative_ids.close()
示例10: upgrade
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def upgrade():
# Add columns, but with null allowed
op.add_column('request', sa.Column('constellation', sa.String(length=25),
nullable=True))
op.add_column('request', sa.Column('region', sa.String(length=25),
nullable=True))
op.add_column('request', sa.Column('system', sa.String(length=25),
nullable=True))
op.create_index('ix_request_constellation', 'request', ['constellation'],
unique=False)
op.create_index('ix_request_region', 'request', ['region'], unique=False)
op.create_index('ix_request_system', 'request', ['system'], unique=False)
# Update existing requests
conn = op.get_bind()
kill_id_sel = select([request.c.id])
kill_ids = conn.execute(kill_id_sel)
for kill_id in kill_ids:
kill_id = kill_id[0]
system_id = get_system_id(kill_id)
system = systems.system_names[system_id]
constellation = systems.systems_constellations[system]
region = systems.constellations_regions[constellation]
update_stmt = update(request)\
.where(request.c.id==op.inline_literal(kill_id))\
.values({
'system': system,
'constellation': constellation,
'region': region,
})
conn.execute(update_stmt)
kill_ids.close()
# Add non-null constraint
op.alter_column('request', 'constellation', nullable=False,
existing_server_default=None,
existing_type=sa.String(length=25))
op.alter_column('request', 'region', nullable=False,
existing_server_default=None,
existing_type=sa.String(length=25))
op.alter_column('request', 'system', nullable=False,
existing_server_default=None,
existing_type=sa.String(length=25))
示例11: _update_atom_details
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def _update_atom_details(self, conn, ad, e_ad):
e_ad.merge(ad)
conn.execute(sql.update(self._tables.atomdetails)
.where(self._tables.atomdetails.c.uuid == e_ad.uuid)
.values(e_ad.to_dict()))
示例12: save_logbook
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def save_logbook(self, book):
try:
logbooks = self._tables.logbooks
with self._engine.begin() as conn:
q = (sql.select([logbooks]).
where(logbooks.c.uuid == book.uuid))
row = conn.execute(q).first()
if row:
e_lb = self._converter.convert_book(row)
self._converter.populate_book(conn, e_lb)
e_lb.merge(book)
conn.execute(sql.update(logbooks)
.where(logbooks.c.uuid == e_lb.uuid)
.values(e_lb.to_dict()))
for fd in book:
e_fd = e_lb.find(fd.uuid)
if e_fd is None:
e_lb.add(fd)
self._insert_flow_details(conn, fd, e_lb.uuid)
else:
self._update_flow_details(conn, fd, e_fd)
return e_lb
else:
conn.execute(sql.insert(logbooks, book.to_dict()))
for fd in book:
self._insert_flow_details(conn, fd, book.uuid)
return book
except sa_exc.DBAPIError:
exc.raise_with_cause(
exc.StorageFailure,
"Failed saving logbook '%s'" % book.uuid)
示例13: _update_stmt_from_query
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def _update_stmt_from_query(mapper, query, values):
upd_values = dict(
(
mapper.column_attrs[key], value
) for key, value in values.items()
)
query = query.enable_eagerloads(False)
context = query._compile_context()
primary_table = context.statement.froms[0]
update_stmt = sql.update(primary_table,
context.whereclause,
upd_values)
return update_stmt
示例14: downgrade
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def downgrade():
# Add type_ and value columns back
op.add_column('modifier',
sa.Column('type_', sa.Enum('absolute', 'percentage',
name='modifier_type')))
op.add_column('modifier', sa.Column('value', sa.Float, nullable=True))
# populate type_ and value columns with data from the subclass tables
abs_select = select([abs_table.c.id, abs_table.c.value])
rel_select = select([rel_table.c.id, rel_table.c.value])
conn = op.get_bind()
for select_stmt in (abs_select, rel_select):
modifier_rows = conn.execute(select_stmt)
for modifier_id, modifier_value in modifier_rows:
if select_stmt == abs_select:
modifier_value = float(modifier_value / 1000000)
type_ = 'absolute'
else:
type_ = 'percentage'
update_stmt = update(modifier)\
.where(modifier.c.id == modifier_id)\
.values({
'value': modifier_value,
'type_': type_
})
conn.execute(update_stmt)
modifier_rows.close()
# Drop the old _type column and the subclass tables
op.drop_column('modifier', '_type')
op.drop_table('absolute_modifier')
op.drop_table('relative_modifier')
# Add not-null constraint back to type_
op.alter_column('modifier',
column_name='type_',
nullable=False,
existing_type=sa.Enum('absolute', 'percentage',
name='modifier_type'))
示例15: _update_flow_details
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import update [as 别名]
def _update_flow_details(self, conn, fd, e_fd):
e_fd.merge(fd)
conn.execute(sql.update(self._tables.flowdetails)
.where(self._tables.flowdetails.c.uuid == e_fd.uuid)
.values(e_fd.to_dict()))
for ad in fd:
e_ad = e_fd.find(ad.uuid)
if e_ad is None:
e_fd.add(ad)
self._insert_atom_details(conn, ad, fd.uuid)
else:
self._update_atom_details(conn, ad, e_ad)