本文整理汇总了Python中mediawords.db.DatabaseHandler.insert方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseHandler.insert方法的具体用法?Python DatabaseHandler.insert怎么用?Python DatabaseHandler.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mediawords.db.DatabaseHandler
的用法示例。
在下文中一共展示了DatabaseHandler.insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mark_as_processed
# 需要导入模块: from mediawords.db import DatabaseHandler [as 别名]
# 或者: from mediawords.db.DatabaseHandler import insert [as 别名]
def mark_as_processed(db: DatabaseHandler, stories_id: int) -> bool:
"""Mark the story as processed by inserting an entry into 'processed_stories'. Return True on success."""
# FIXME upsert instead of inserting a potential duplicate
if isinstance(stories_id, bytes):
stories_id = decode_object_from_bytes_if_needed(stories_id)
stories_id = int(stories_id)
log.debug("Marking story ID %d as processed..." % stories_id)
try:
db.insert(table='processed_stories', insert_hash={'stories_id': stories_id})
except Exception as ex:
log.warning("Unable to insert story ID %d into 'processed_stories': %s" % (stories_id, str(ex),))
return False
else:
return True
示例2: update_user
# 需要导入模块: from mediawords.db import DatabaseHandler [as 别名]
# 或者: from mediawords.db.DatabaseHandler import insert [as 别名]
def update_user(db: DatabaseHandler, user_updates: ModifyUser) -> None:
"""Update an existing user."""
if not user_updates:
raise McAuthProfileException("Existing user is undefined.")
# Check if user exists
try:
user = user_info(db=db, email=user_updates.email())
except Exception:
raise McAuthProfileException('User with email address "%s" does not exist.' % user_updates.email())
db.begin()
if user_updates.full_name() is not None:
db.query("""
UPDATE auth_users
SET full_name = %(full_name)s
WHERE email = %(email)s
""", {
'full_name': user_updates.full_name(),
'email': user_updates.email(),
})
if user_updates.notes() is not None:
db.query("""
UPDATE auth_users
SET notes = %(notes)s
WHERE email = %(email)s
""", {
'notes': user_updates.notes(),
'email': user_updates.email(),
})
if user_updates.active() is not None:
db.query("""
UPDATE auth_users
SET active = %(active)s
WHERE email = %(email)s
""", {
'active': bool(int(user_updates.active())),
'email': user_updates.email(),
})
if user_updates.password() is not None:
try:
change_password(
db=db,
email=user_updates.email(),
new_password=user_updates.password(),
new_password_repeat=user_updates.password_repeat(),
do_not_inform_via_email=True,
)
except Exception as ex:
db.rollback()
raise McAuthProfileException("Unable to change password: %s" % str(ex))
if user_updates.weekly_requests_limit() is not None:
db.query("""
UPDATE auth_user_limits
SET weekly_requests_limit = %(weekly_requests_limit)s
WHERE auth_users_id = %(auth_users_id)s
""", {
'weekly_requests_limit': user_updates.weekly_requests_limit(),
'auth_users_id': user.user_id(),
})
if user_updates.weekly_requested_items_limit() is not None:
db.query("""
UPDATE auth_user_limits
SET weekly_requested_items_limit = %(weekly_requested_items_limit)s
WHERE auth_users_id = %(auth_users_id)s
""", {
'weekly_requested_items_limit': user_updates.weekly_requested_items_limit(),
'auth_users_id': user.user_id(),
})
if user_updates.role_ids() is not None:
db.query("""
DELETE FROM auth_users_roles_map
WHERE auth_users_id = %(auth_users_id)s
""", {'auth_users_id': user.user_id()})
for auth_roles_id in user_updates.role_ids():
db.insert(table='auth_users_roles_map', insert_hash={
'auth_users_id': user.user_id(),
'auth_roles_id': auth_roles_id,
})
db.commit()