本文整理汇总了Python中sqlalchemy.sql.expression.column函数的典型用法代码示例。如果您正苦于以下问题:Python column函数的具体用法?Python column怎么用?Python column使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了column函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: migrate
def migrate(self):
self.add_userid_column()
self.migrate_data()
self.remove_watcherid_column()
self.make_userid_column_required()
self.notifications_table = table("notifications", column("id"), column("activity_id"), column("watcher_id"))
开发者ID:4teamwork,项目名称:opengever.core,代码行数:7,代码来源:to4505.py
示例2: migrate_data
def migrate_data(self):
activities_table = table(
"activities", column("id"), column("kind"), column("summary"), column("title"), column("description")
)
activities_translation_table = table(
"activities_translation",
column("id"),
column("locale"),
column("title"),
column("label"),
column("summary"),
column("description"),
)
activities = self.connection.execute(activities_table.select()).fetchall()
for activity in activities:
self.execute(
activities_translation_table.insert(
values={
"id": activity.id,
"locale": DEFAULT_LOCALE,
"title": activity.title,
# the label column is new so we use the kind
# for existing entries
"label": activity.kind,
"summary": activity.summary,
"description": activity.description,
}
)
)
开发者ID:4teamwork,项目名称:opengever.core,代码行数:31,代码来源:to4501.py
示例3: add_meeting_sequence_to_period
def add_meeting_sequence_to_period(self):
self.op.add_column("periods", Column("meeting_sequence_number", Integer, nullable=True))
periods_table = table("periods", column("id"), column("meeting_sequence_number"))
self.execute(periods_table.update().values(meeting_sequence_number=0))
self.op.alter_column("periods", "meeting_sequence_number", existing_type=Integer, nullable=False)
开发者ID:4teamwork,项目名称:opengever.core,代码行数:7,代码来源:to4622.py
示例4: raise_column_length
def raise_column_length(self):
# add new column with the new size
self.op.add_column(
'favorites',
Column('tmp_plone_uid', String(UID_LENGTH)))
# migrate_data
_table = table(
'favorites',
column("id"),
column('plone_uid'),
column('tmp_plone_uid'))
items = self.connection.execute(_table.select()).fetchall()
for item in items:
self.execute(
_table.update()
.values(tmp_plone_uid=item.plone_uid)
.where(_table.columns.id == item.id)
)
# drop old column
self.op.drop_column('favorites', 'plone_uid')
# rename new column
self.op.alter_column('favorites',
'tmp_plone_uid',
new_column_name='plone_uid')
开发者ID:4teamwork,项目名称:opengever.core,代码行数:29,代码来源:upgrade.py
示例5: downgrade
def downgrade():
op.create_table(
'planet_name',
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('name', sa.String, nullable=False),
)
op.create_unique_constraint('uc_planet_name', 'planet_name', ['name'])
op.add_column('libration', sa.Column(
'first_planet_name_id', sa.Integer, sa.ForeignKey('planet_name.id'), nullable=True
))
op.add_column('libration', sa.Column(
'second_planet_name_id', sa.Integer, sa.ForeignKey('planet_name.id'), nullable=True
))
planet_name_table = table('planet_name', column('id', sa.Integer), column('name', sa.String))
op.bulk_insert(planet_name_table, [
{'id': 9, 'name': 'PLUTO'},
{'id': 8, 'name': 'NEPTUNE'},
{'id': 7, 'name': 'URANUS'},
{'id': 6, 'name': 'SATURN'},
{'id': 5, 'name': 'JUPITER'},
{'id': 4, 'name': 'MARS'},
{'id': 3, 'name': 'EARTHMOO'},
{'id': 2, 'name': 'VENUS'},
{'id': 1, 'name': 'MERCURY'},
])
op.execute('UPDATE libration SET first_planet_name_id=5, second_planet_name_id=6')
op.alter_column('libration', 'first_planet_name_id', nullable=False)
op.alter_column('libration', 'second_planet_name_id', nullable=False)
op.drop_constraint('libration_resonance_id_key', 'libration')
op.create_unique_constraint('uc_resonance_planet_names', 'libration',
['resonance_id', 'first_planet_name_id', 'second_planet_name_id'])
开发者ID:4xxi,项目名称:resonances,代码行数:34,代码来源:2802742e9993_removing_planet_name_table.py
示例6: get_existing_id_lookup
def get_existing_id_lookup(self):
contact_table = table(
"contacts",
column('id'),
column('former_contact_id'))
stmt = select([contact_table.c.former_contact_id, contact_table.c.id])
return {key: value for (key, value) in self.db_session.execute(stmt)}
开发者ID:4teamwork,项目名称:opengever.core,代码行数:7,代码来源:object_syncer.py
示例7: add_bucket_grouping_to_query
def add_bucket_grouping_to_query(self, q, q_entities, entity, mapped_entity):
# Get min, max if not provided.
entity_min = 0
entity_max = 0
if (not entity.has_key('min') or not entity.has_key('max')):
entity_min, entity_max = self.get_entity_min_max(entity)
# Override calculated min/max if values were provided.
if entity.has_key('min'): entity_min = entity.get('min')
if entity.has_key('max'): entity_max = entity.get('max')
num_buckets = entity.get('num_buckets', 10)
entity_range = entity_max - entity_min
bucket_width = (entity_max - entity_min)/float(num_buckets)
# Get bucket field entities.
# Can use the line below in case db doesn't have width_bucket function.
#bucket_id_entity = func.greatest(func.round( (((mapped_entity - entity_min)/entity_range) * num_buckets ) - .5) + 1, num_buckets).label(self.get_bucket_id_label(entity))
bucket_id_entity = func.width_bucket(mapped_entity, entity_min, entity_max, num_buckets).label(self.get_bucket_id_label(entity))
q_entities.add(bucket_id_entity)
bucket_label_entity = case(
[(bucket_id_entity == num_buckets + 1, '[' + cast( entity_max, String) + ', ...)')],
else_ = '[' + cast(entity_min + bucket_width * (bucket_id_entity - 1), String ) + ', ' + cast(entity_min + bucket_width * (bucket_id_entity), String) + ')' ).label(entity['label'])
q_entities.add(bucket_id_entity)
q_entities.add(bucket_label_entity)
q = q.group_by(column(bucket_id_entity._label), column(bucket_label_entity._label))
return q
开发者ID:adorsk-noaa,项目名称:SASI-model,代码行数:31,代码来源:sa_dao.py
示例8: upgrade
def upgrade():
op.create_table(
"planet_name", sa.Column("id", sa.Integer, primary_key=True), sa.Column("name", sa.String, nullable=False)
)
op.create_unique_constraint("uc_planet_name", "planet_name", ["name"])
op.add_column(
"libration", sa.Column("first_planet_name_id", sa.Integer, sa.ForeignKey("planet_name.id"), nullable=True)
)
op.add_column(
"libration", sa.Column("second_planet_name_id", sa.Integer, sa.ForeignKey("planet_name.id"), nullable=True)
)
planet_name_table = table("planet_name", column("id", sa.Integer), column("name", sa.String))
op.bulk_insert(
planet_name_table,
[
{"id": 9, "name": "PLUTO"},
{"id": 8, "name": "NEPTUNE"},
{"id": 7, "name": "URANUS"},
{"id": 6, "name": "SATURN"},
{"id": 5, "name": "JUPITER"},
{"id": 4, "name": "MARS"},
{"id": 3, "name": "EARTHMOO"},
{"id": 2, "name": "VENUS"},
{"id": 1, "name": "MERCURY"},
],
)
op.execute("UPDATE libration SET first_planet_name_id=5, second_planet_name_id=6")
开发者ID:4xxi,项目名称:resonances,代码行数:29,代码来源:c6b695987112_add_planet_names_table.py
示例9: insert_default_value
def insert_default_value(self, tablename):
contact_table = table(
tablename,
column("id"),
column("is_active"))
self.connection.execute(
contact_table.update().values(is_active=True))
开发者ID:4teamwork,项目名称:opengever.core,代码行数:8,代码来源:upgrade.py
示例10: get_watcherid_userid_mapping
def get_watcherid_userid_mapping(self):
mapping = {}
watchers_table = table("watchers", column("id"), column("user_id"))
watchers = self.connection.execute(watchers_table.select()).fetchall()
for watcher in watchers:
mapping[watcher.id] = watcher.user_id
return mapping
开发者ID:4teamwork,项目名称:opengever.core,代码行数:9,代码来源:to4505.py
示例11: insert_placeholders
def insert_placeholders(self):
"""Fill empty MailAddress with a placeholder.
"""
mailaddress_table = table('mail_addresses',
column("id"),
column("address"))
self.execute(mailaddress_table.update()
.values(address=EMPTY_ADDRESS_PLACEHOLDER)
.where(mailaddress_table.columns.address == None))
开发者ID:4teamwork,项目名称:opengever.core,代码行数:10,代码来源:upgrade.py
示例12: migrate_data
def migrate_data(self):
"""Temporarily insert placeholders as repository_folder_title,
the real value will be inserted by the 4633 upgradestep.
"""
default_language = get_preferred_language_code()
proposal_table = table("proposals", column("id"), column("repository_folder_title"), column("language"))
self.execute(proposal_table.update().values(repository_folder_title=u"-"))
self.execute(proposal_table.update().values(language=default_language))
开发者ID:4teamwork,项目名称:opengever.core,代码行数:10,代码来源:to4632.py
示例13: migrate_data
def migrate_data(self):
"""Temporarily insert placeholders as dossier_reference_numbers,
the real value will be inserted by the 4603 upgradestep.
"""
proposal_table = table("proposals",
column("id"),
column("dossier_reference_number"))
self.execute(
proposal_table.update().values(dossier_reference_number=u'-'))
开发者ID:4teamwork,项目名称:opengever.core,代码行数:10,代码来源:to4602.py
示例14: insert_default_modified
def insert_default_modified(self):
"""Insert time of migration as last modified timestamp."""
meeting_table = table(
'meetings',
column('id'),
column('modified'),
)
self.execute(meeting_table.update().values(modified=utcnow_tz_aware()))
开发者ID:4teamwork,项目名称:opengever.core,代码行数:10,代码来源:to4620.py
示例15: add_admin_user
def add_admin_user():
stmt = table('users',
column('username'),
column('_password_hash')).insert().\
values\
(
username=sa.bindparam('username'),
_password_hash=sa.bindparam('_password_hash'),
)
op.get_bind().execute(stmt,[dict(username='admin',_password_hash=pw('admin'))])
开发者ID:jstacoder,项目名称:angular-editor,代码行数:10,代码来源:511225667a1c_adding_emails_table_and_users_emails_.py
示例16: get_contact_mapping
def get_contact_mapping(self):
if not self._contact_mapping:
contact_table = table(
"contacts",
column('id'),
column('former_contact_id'))
stmt = select([contact_table.c.former_contact_id, contact_table.c.id])
self._contact_mapping = {key: value for (key, value)
in self.db_session.execute(stmt)}
return self._contact_mapping
开发者ID:4teamwork,项目名称:opengever.core,代码行数:11,代码来源:object_syncer.py
示例17: add_decision_sequence_to_period
def add_decision_sequence_to_period(self):
self.op.add_column(
'periods',
Column('decision_sequence_number', Integer, nullable=True))
periods_table = table(
'periods',
column('id'), column('decision_sequence_number'))
self.execute(periods_table.update().values(decision_sequence_number=0))
self.op.alter_column('periods', 'decision_sequence_number',
existing_type=Integer,
nullable=False)
开发者ID:4teamwork,项目名称:opengever.core,代码行数:13,代码来源:to4621.py
示例18: migrate_data
def migrate_data(self):
watcher_id_mapping = self.get_watcherid_userid_mapping()
notifications_table = table(
"notifications", column("id"), column("activity_id"), column("watcher_id"), column("userid")
)
notifications = self.connection.execute(notifications_table.select()).fetchall()
for notification in notifications:
userid = watcher_id_mapping[notification.watcher_id]
self.execute(
notifications_table.update()
.values(userid=userid)
.where(notifications_table.columns.id == notification.id)
)
开发者ID:4teamwork,项目名称:opengever.core,代码行数:14,代码来源:to4505.py
示例19: insert_org_units_group_id
def insert_org_units_group_id(self):
"""Insert the current org-unit's group_id for all committees.
Bye default we use the users group. This choice is somewhat arbitrary,
but id does not really matter since meeting is not in production when
this upgrade is executed.
"""
proposal_table = table("committees",
column("id"),
column("group_id"))
group_id = get_current_org_unit().users_group.groupid
self.execute(
proposal_table.update().values(group_id=group_id))
开发者ID:4teamwork,项目名称:opengever.core,代码行数:15,代码来源:to4608.py
示例20: migrate_held_state
def migrate_held_state(self):
"""The state held lost its relevance and is equivalent to pending.
The migrations thus resets all meetings in the state held to the state
pending.
"""
meeting_table = table("meetings",
column("id"),
column("workflow_state"))
self.execute(
meeting_table.update()
.values(workflow_state='pending')
.where(meeting_table.c.workflow_state == 'held'))
开发者ID:4teamwork,项目名称:opengever.core,代码行数:15,代码来源:to4616.py
注:本文中的sqlalchemy.sql.expression.column函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论