Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def list_named_queries(verbose):
"""List of all named queries.
Returns (title, rows, headers, status)"""
if not verbose:
rows = [[r] for r in NamedQueries.instance.list()]
headers = ["Name"]
else:
headers = ["Name", "Query"]
rows = [[r, NamedQueries.instance.get(r)]
for r in NamedQueries.instance.list()]
if not rows:
status = NamedQueries.instance.usage
else:
status = ''
return [('', rows, headers, status)]
def save_named_query(pattern, **_):
"""Save a new named query.
Returns (title, rows, headers, status)"""
usage = 'Syntax: \\ns name query.\n\n' + NamedQueries.instance.usage
if not pattern:
return [(None, None, None, usage)]
name, _, query = pattern.partition(' ')
# If either name or query is missing then print the usage and complain.
if (not name) or (not query):
return [(None, None, None,
usage + 'Err: Both name and query are required.')]
NamedQueries.instance.save(name, query)
return [(None, None, None, "Saved.")]