本文整理汇总了Python中core.db.connection.DataHubConnection.export_query方法的典型用法代码示例。如果您正苦于以下问题:Python DataHubConnection.export_query方法的具体用法?Python DataHubConnection.export_query怎么用?Python DataHubConnection.export_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.db.connection.DataHubConnection
的用法示例。
在下文中一共展示了DataHubConnection.export_query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export_query
# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import export_query [as 别名]
def export_query(repo_base, query, file_path, file_format="CSV", delimiter=",", header=True):
superuser_con = DataHubConnection(
user=settings.DATABASES["default"]["USER"],
password=settings.DATABASES["default"]["USER"],
repo_base=repo_base,
)
return superuser_con.export_query(
query=query, file_path=file_path, file_format=file_format, delimiter=delimiter, header=header
)
示例2: export_query
# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import export_query [as 别名]
def export_query(repo_base, query, file_path, file_format='CSV',
delimiter=',', header=True):
superuser_con = DataHubConnection(
user=settings.DATABASES['default']['USER'],
password=settings.DATABASES['default']['USER'],
repo_base=repo_base)
return superuser_con.export_query(
query=query,
file_path=file_path,
file_format=file_format,
delimiter=delimiter,
header=header)
示例3: __init__
# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import export_query [as 别名]
#.........这里部分代码省略.........
return card
def export_card(self, repo, file_name, card_name, file_format='CSV'):
"""
Exports the results of a card to a new file in the repo.
Any existing file with that name is overwritten.
Raises PermissionDenied on insufficient privileges or bad query.
"""
DataHubManager.has_repo_file_privilege(
self.username, self.repo_base, repo, 'write')
card = Card.objects.get(repo_base=self.repo_base,
repo_name=repo, card_name=card_name)
query = card.query
# to export a card, the user must be able to successfully execute
# the query from their own database user.
try:
self.execute_sql(query)
except Exception:
raise PermissionDenied(
'Either missing required privileges or bad query')
# create the user data folder if it doesn't already exist
DataHubManager.create_user_data_folder(self.repo_base, repo)
file_name = clean_file_name(file_name)
file_path = user_data_path(
self.repo_base, repo, file_name, file_format)
self.user_con.export_query(query=query,
file_path=file_path,
file_format=file_format)
def delete_card(self, repo, card_name):
"""
Deletes a card from a repo.
Raises Card.DoesNotExist for invalid card_name.
Raises PermissionDenied on insufficient privileges.
"""
DataHubManager.has_repo_file_privilege(
self.username, self.repo_base, repo, 'write')
card = Card.objects.get(repo_base=self.repo_base,
repo_name=repo, card_name=card_name)
return card.delete()
def limit_and_offset_select_query(self, query, limit, offset):
"""
Modifies select queries, adding limits and offsets.
Used primarily for pagination
"""
return self.user_con.limit_and_offset_select_query(
query=query, limit=limit, offset=offset)
def paginate_query(self, query, current_page, rows_per_page):
"""
Set variables for query pagination, limiting query statement
to just the section of the table that will be displayed
"""
explanation = self.explain_query(query)