70def init(engine_settings):
71 global _connection # pylint: disable=global-statement
73 if 'query_str' not in engine_settings:
74 raise ValueError('query_str cannot be empty')
76 if not engine_settings['query_str'].lower().startswith('select '):
77 raise ValueError('only SELECT query is supported')
79 _connection = mariadb.connect(database=database, user=username, password=password, host=host, port=port)
82def search(query, params):
83 query_params = {'query': query}
84 query_to_run = query_str + ' LIMIT {0} OFFSET {1}'.format(limit, (params['pageno'] - 1) * limit)
85 logger.debug("SQL Query: %s", query_to_run)
87 with _connection.cursor() as cur:
88 cur.execute(query_to_run, query_params)
90 col_names = [i[0] for i in cur.description]
92 result = dict(zip(col_names, map(str, res)))
93 result['template'] = result_template
94 results.append(result)