57def init(engine_settings):
58 global _connection # pylint: disable=global-statement
60 if 'query_str' not in engine_settings:
61 raise ValueError('query_str cannot be empty')
63 if not engine_settings['query_str'].lower().startswith('select '):
64 raise ValueError('only SELECT query is supported')
66 _connection = psycopg2.connect(
75def search(query, params):
76 query_params = {'query': query}
77 query_to_run = query_str + ' LIMIT {0} OFFSET {1}'.format(limit, (params['pageno'] - 1) * limit)
80 with _connection.cursor() as cur:
81 cur.execute(query_to_run, query_params)
82 return _fetch_results(cur)
85def _fetch_results(cur):
90 titles = [column_desc.name for column_desc in cur.description]
93 result = dict(zip(titles, map(str, res)))
94 result['template'] = result_template
95 results.append(result)
98 except psycopg2.ProgrammingError: