本文整理汇总了Python中database.database.DatabaseInterface.tables方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseInterface.tables方法的具体用法?Python DatabaseInterface.tables怎么用?Python DatabaseInterface.tables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.database.DatabaseInterface
的用法示例。
在下文中一共展示了DatabaseInterface.tables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_all_project_ids
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def read_all_project_ids(project_selection=ProjectSelection.Active,
max_revision_id=None) -> List[int]:
"""
Reads all project IDs from the database
:param project_selection: Search for active, inactive or all project
:param max_revision_id: Maximum revision ID for the search ("None" for latest revision)
:return: List of project IDs
"""
connection = DatabaseInterface.create_connection()
if max_revision_id is None:
max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
connection)
# Reads all project IDs from the database
projects = None
if max_revision_id is not None:
projects = DatabaseInterface.tables().project_information.read_all_project_ids(
connection,
project_selection,
max_revision_id)
return projects
示例2: deactivate_project
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def deactivate_project(requested_by_user: int, project_id: int) -> bool:
"""
Deactivates an active project
:param requested_by_user: ID of the user that requested modification of the user
:param project_id: ID of the project that should be deactivated
:return: Success or failure
"""
connection = DatabaseInterface.create_connection()
try:
success = connection.begin_transaction()
# Start a new revision
revision_id = None
if success:
revision_id = DatabaseInterface.tables().revision.insert_row(
connection,
datetime.datetime.utcnow(),
requested_by_user)
if revision_id is None:
success = False
# Read project
project = None
if success:
project = ProjectManagementInterface.__read_project_by_id(connection,
project_id,
revision_id)
if project is None:
success = False
elif not project["active"]:
# Error, project is already inactive
success = False
# Deactivate project
if success:
success = DatabaseInterface.tables().project_information.insert_row(
connection,
project_id,
project["short_name"],
project["full_name"],
project["description"],
False,
revision_id)
if success:
connection.commit_transaction()
else:
connection.rollback_transaction()
except:
connection.rollback_transaction()
raise
return success
示例3: read_all_tracker_field_ids
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def read_all_tracker_field_ids(tracker_id: int,
tracker_field_selection=TrackerFieldSelection.Active,
max_revision_id=None) -> List[int]:
"""
Reads all tracker field IDs from the database
:param tracker_id: ID of the tracker
:param tracker_field_selection: Search for active, inactive or all tracker
:param max_revision_id: Maximum revision ID for the search ("None" for latest
revision)
:return: List of tracker field IDs
"""
connection = DatabaseInterface.create_connection()
if max_revision_id is None:
max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
connection)
# Reads all tracker field IDs from the database
tracker_fields = None
if max_revision_id is not None:
tracker_fields = \
DatabaseInterface.tables().tracker_field_information.read_all_tracker_field_ids(
connection,
tracker_id,
tracker_field_selection,
max_revision_id)
return tracker_fields
示例4: activate_tracker
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def activate_tracker(requested_by_user: int, tracker_id: int) -> bool:
"""
Activates an inactive tracker
:param requested_by_user: ID of the user that requested modification of the user
:param tracker_id: ID of the tracker that should be activated
:return: Success or failure
"""
connection = DatabaseInterface.create_connection()
try:
success = connection.begin_transaction()
# Start a new revision
revision_id = None
if success:
revision_id = DatabaseInterface.tables().revision.insert_row(
connection,
datetime.datetime.utcnow(),
requested_by_user)
if revision_id is None:
success = False
# Read tracker
tracker = None
if success:
tracker = TrackerManagementInterface.__read_tracker_by_id(connection,
tracker_id,
revision_id)
if tracker is None:
success = False
elif tracker["active"]:
# Error, tracker is already active
success = False
# Activate tracker
if success:
success = DatabaseInterface.tables().tracker_information.insert_row(
connection,
tracker_id,
tracker["short_name"],
tracker["full_name"],
tracker["description"],
True,
revision_id)
if success:
connection.commit_transaction()
else:
connection.rollback_transaction()
except:
connection.rollback_transaction()
raise
return success
示例5: __create_tracker
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def __create_tracker(connection: Connection,
project_id: int,
short_name: str,
full_name: str,
description: str,
revision_id: int) -> Optional[int]:
"""
Creates a new tracker
:param connection: Database connection
:param project_id: ID of the project
:param short_name: Tracker's short name
:param full_name: Tracker's full name
:param description: Tracker's description
:param revision_id: Revision ID
:return: Tracker ID of the newly created tracker
"""
# Check if a tracker with the same short name already exists
tracker = TrackerManagementInterface.__read_tracker_by_short_name(connection,
short_name,
revision_id)
if tracker is not None:
return None
# Check if a tracker with the same full name already exists
tracker = TrackerManagementInterface.__read_tracker_by_full_name(connection,
full_name,
revision_id)
if tracker is not None:
return None
# Create the tracker in the new revision
tracker_id = DatabaseInterface.tables().tracker.insert_row(connection, project_id)
if tracker_id is None:
return None
# Add tracker information to the tracker
tracker_information_id = DatabaseInterface.tables().tracker_information.insert_row(
connection,
tracker_id,
short_name,
full_name,
description,
True,
revision_id)
if tracker_information_id is None:
return None
return tracker_id
示例6: __create_project
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def __create_project(connection: Connection,
short_name: str,
full_name: str,
description: str,
revision_id: int) -> Optional[int]:
"""
Creates a new project
:param connection: Database connection
:param short_name: Project's short name
:param full_name: Project's full name
:param description: Project's description
:param revision_id: Revision ID
:return: Project ID of the newly created project
"""
# Check if a project with the same short name already exists
project = ProjectManagementInterface.__read_project_by_short_name(connection,
short_name,
revision_id)
if project is not None:
return None
# Check if a project with the same full name already exists
project = ProjectManagementInterface.__read_project_by_full_name(connection,
full_name,
revision_id)
if project is not None:
return None
# Create the project in the new revision
project_id = DatabaseInterface.tables().project.insert_row(connection)
if project_id is None:
return None
# Add project information to the project
project_information_id = DatabaseInterface.tables().project_information.insert_row(
connection,
project_id,
short_name,
full_name,
description,
True,
revision_id)
if project_information_id is None:
return None
return project_id
示例7: read_user_by_id
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def read_user_by_id(connection: Connection, user_id: int) -> Optional[dict]:
"""
Reads a user (active or inactive) that matches the specified user ID
:param connection: Database connection
:param user_id: ID of the user
:return: User information object
Returned dictionary contains items:
- id
- user_name
- display_name
- email
- active
"""
# Read the users that match the search attribute
users = DatabaseInterface.tables().user.read_users_by_attribute(connection,
"id",
user_id,
UserSelection.All)
# Return a user only if exactly one was found
user = None
if users is not None:
if len(users) == 1:
user = users[0]
return user
示例8: read_project_by_id
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def read_project_by_id(project_id: int, max_revision_id=None) -> Optional[dict]:
"""
Reads a project (active or inactive) that matches the specified project ID
:param project_id: ID of the project
:param max_revision_id: Maximum revision ID for the search ("None" for latest revision)
:return: Project information object
Returned dictionary contains items:
- id
- short_name
- full_name
- description
- active
- revision_id
"""
connection = DatabaseInterface.create_connection()
if max_revision_id is None:
max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
connection)
# Read a project that matches the specified project ID
project = None
if max_revision_id is not None:
project = ProjectManagementInterface.__read_project_by_id(connection,
project_id,
max_revision_id)
return project
示例9: __read_user_by_display_name
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def __read_user_by_display_name(connection: Connection, display_name: str) -> Optional[dict]:
"""
Reads an active user that matches the specified display name
:param display_name: User's display name
:return: User information object
Returned dictionary contains items:
- id
- user_name
- display_name
- email
- active
"""
# Read the users that match the search attribute
users = DatabaseInterface.tables().user.read_users_by_attribute(connection,
"display_name",
display_name,
UserSelection.Active)
# Return a user only if exactly one was found
user = None
if users is not None:
if len(users) == 1:
user = users[0]
return user
示例10: read_tracker_by_id
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def read_tracker_by_id(tracker_id: int, max_revision_id=None) -> Optional[dict]:
"""
Reads a tracker (active or inactive) that matches the specified tracker ID
:param tracker_id: ID of the tracker
:param max_revision_id: Maximum revision ID for the search ("None" for latest revision)
:return: Tracker information object
Returned dictionary contains items:
- id
- project_id
- short_name
- full_name
- description
- active
- revision_id
"""
connection = DatabaseInterface.create_connection()
if max_revision_id is None:
max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
connection)
# Read a tracker that matches the specified tracker ID
tracker = None
if max_revision_id is not None:
tracker = TrackerManagementInterface.__read_tracker_by_id(connection,
tracker_id,
max_revision_id)
return tracker
示例11: read_tracker_fields_by_display_name
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def read_tracker_fields_by_display_name(display_name: str,
max_revision_id=None) -> List[dict]:
"""
Reads all active and inactive tracker fields that match the specified display name
:param display_name: Tracker field's display name
:param max_revision_id: Maximum revision ID for the search ("None" for latest revision)
:return: Tracker field information of all tracker fields that match the search attribute
Each dictionary in the returned list contains items:
- id
- tracker_id
- name
- display_name
- description
- field_type
- required
- active
- revision_id
"""
connection = DatabaseInterface.create_connection()
if max_revision_id is None:
max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
connection)
# Read tracker fields that match the specified display name
tracker_fields = list()
if max_revision_id is not None:
tracker_field_information_list = \
DatabaseInterface.tables().tracker_field_information.read_information(
connection,
"display_name",
display_name,
TrackerFieldSelection.All,
max_revision_id)
for tracker_field_information in tracker_field_information_list:
tracker_fields.append(
TrackerFieldManagementInterface.__parse_tracker_field_information(
tracker_field_information))
return tracker_fields
示例12: update_user_information
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def update_user_information(user_to_modify: int,
user_name: str,
display_name: str,
email: str,
active: bool) -> bool:
"""
Updates user's information
:param user_to_modify: ID of the user that should be modified
:param user_name: User's new user name
:param display_name: User's new display name
:param email: User's new email address
:param active: User's new state (active or inactive)
:return: Success or failure
"""
connection = DatabaseInterface.create_connection()
try:
success = connection.begin_transaction()
# Check if there is already an existing user with the same user name
if success:
user = UserManagementInterface.__read_user_by_user_name(connection, user_name)
if user is not None:
if user["id"] != user_to_modify:
success = False
# Check if there is already an existing user with the same display name
if success:
user = UserManagementInterface.__read_user_by_display_name(connection,
display_name)
if user is not None:
if user["id"] != user_to_modify:
success = False
# Update user's information
if success:
success = DatabaseInterface.tables().user.update_row(connection,
user_to_modify,
user_name,
display_name,
email,
active)
if success:
connection.commit_transaction()
else:
connection.rollback_transaction()
except:
connection.rollback_transaction()
raise
return success
示例13: read_all_user_ids
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def read_all_user_ids(user_selection=UserSelection.Active) -> List[int]:
"""
Reads all user IDs from the database
:param user_selection: Search for active, inactive or all users
:return: List of user IDs
"""
connection = DatabaseInterface.create_connection()
return DatabaseInterface.tables().user.read_all_ids(connection, user_selection)
示例14: read_trackers_by_full_name
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def read_trackers_by_full_name(full_name: str,
max_revision_id=None) -> List[dict]:
"""
Reads all active and inactive trackers that match the specified full name
:param full_name: Tracker's full name
:param max_revision_id: Maximum revision ID for the search ("None" for latest revision)
:return: Tracker information of all trackers that match the search attribute
Each dictionary in the returned list contains items:
- id
- project_id
- short_name
- full_name
- description
- active
- revision_id
"""
connection = DatabaseInterface.create_connection()
if max_revision_id is None:
max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
connection)
# Read trackers that match the specified full name
trackers = list()
if max_revision_id is not None:
tracker_information_list = \
DatabaseInterface.tables().tracker_information.read_information(
connection,
"full_name",
full_name,
TrackerSelection.All,
max_revision_id)
for tracker_information in tracker_information_list:
trackers.append(TrackerManagementInterface.__parse_tracker_information(
tracker_information))
return trackers
示例15: delete_session_token
# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import tables [as 别名]
def delete_session_token(connection: Connection, token: str) -> bool:
"""
Deletes the specified session token
:param connection: Database connection
:param token: Session's token value
:return: Success or failure
"""
# Check if the specified token is valid
existing_session_token = UserManagementInterface.read_session_token(connection, token)
if existing_session_token is None:
# Error, invalid token
return False
# Delete the token from the database
DatabaseInterface.tables().session_token.delete_row_by_token(connection, token)
return True