本文整理汇总了Python中core.db.connection.DataHubConnection.select_table_query方法的典型用法代码示例。如果您正苦于以下问题:Python DataHubConnection.select_table_query方法的具体用法?Python DataHubConnection.select_table_query怎么用?Python DataHubConnection.select_table_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.db.connection.DataHubConnection
的用法示例。
在下文中一共展示了DataHubConnection.select_table_query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import select_table_query [as 别名]
#.........这里部分代码省略.........
res = self.limit_and_offset_select_query(
query=query, limit=rows_per_page, offset=offset)
select_query = res['select_query']
query = res['query']
# actually make the query
column_names = None # top columns
rows = None # in tuple form
res = self.execute_sql(query)
# determine the column_names and rows
if select_query or res['row_count'] > 0: # normal case
column_names = [field['name'] for field in res['fields']]
rows = res['tuples']
else: # query just returned a bool
column_names = ['status']
rows = [['success' if res['status'] else res['error']]]
result = {
'num_rows': num_rows,
'time_cost': time_cost,
'byte_width': byte_width,
'total_pages': total_pages,
'start_page': start_page,
'end_page': end_page,
'column_names': column_names,
'rows': rows,
'select_query': select_query
}
return result
def select_table_query(self, repo, table):
"""
Return a database query for selecting the table.
Necessary for keeping sq/nosql queries out of views.
"""
return self.user_con.select_table_query(
repo_base=self.repo_base, repo=repo, table=table)
'''
Static methods that don't require permissions
'''
@staticmethod
def create_user_data_folder(repo_base, repo=''):
"""
Creates a user data folder for the given user.
Optionally accepts a specific repo's folder to create.
Fails silently if the folder already exists.
Returns the deleted path.
"""
repo_dir = os.path.abspath(
os.path.join(os.sep, 'user_data', repo_base, repo))
try:
os.makedirs(repo_dir)
except OSError as e:
if e.errno != errno.EEXIST:
raise
return repo_dir
@staticmethod
def delete_user_data_folder(repo_base, repo=''):
示例2: __init__
# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import select_table_query [as 别名]
#.........这里部分代码省略.........
res = self.limit_and_offset_select_query(
query=query, limit=rows_per_page, offset=offset)
select_query = res['select_query']
query = res['query']
# actually make the query
column_names = None # top columns
rows = None # in tuple form
res = self.execute_sql(query)
# determine the column_names and rows
if select_query or res['row_count'] > 0: # normal case
column_names = [field['name'] for field in res['fields']]
rows = res['tuples']
else: # query just returned a bool
column_names = ['status']
rows = [['success' if res['status'] else res['error']]]
result = {
'num_rows': num_rows,
'time_cost': time_cost,
'byte_width': byte_width,
'total_pages': total_pages,
'start_page': start_page,
'end_page': end_page,
'column_names': column_names,
'rows': rows,
'select_query': select_query
}
return result
def select_table_query(self, repo, table):
"""
Return a database query for selecting the table.
Necessary for keeping sq/nosql queries out of views.
"""
return self.user_con.select_table_query(
repo_base=self.repo_base, repo=repo, table=table)
def import_rows(self, repo, table, rows, delimiter=',', header=False):
delimiter = delimiter.decode('string_escape')
# column names are the extracted
columns = rows[0].split(delimiter)
if not header:
# if there's not a header, they're replaced with the word 'col'
columns = ['col' for c in columns]
columns = rename_duplicates(columns)
# prepare params and create the table
params = [{'column_name': c, 'data_type': 'text'} for c in columns]
self.create_table(repo=repo, table=table, params=params)
# now, insert the data and return the result
return self.user_con.import_rows(repo, table, rows, delimiter, header)
"""
Static methods that don't require permissions
"""
@staticmethod
def create_user_data_folder(repo_base, repo=''):
"""