63def init(engine_settings):
64 global _connection # pylint: disable=global-statement
66 if 'query_str' not in engine_settings:
67 raise ValueError('query_str cannot be empty')
69 if not engine_settings['query_str'].lower().startswith('select '):
70 raise ValueError('only SELECT query is supported')
72 _connection = mariadb.connect(database=database, user=username, password=password, host=host, port=port)
75def search(query, params) -> EngineResults:
76 query_params = {'query': query}
77 query_to_run = query_str + ' LIMIT {0} OFFSET {1}'.format(limit, (params['pageno'] - 1) * limit)
78 logger.debug("SQL Query: %s", query_to_run)
81 with _connection.cursor() as cur:
82 cur.execute(query_to_run, query_params)
83 col_names = [i[0] for i in cur.description]
85 kvmap = dict(zip(col_names, map(str, row)))
86 res.add(res.types.KeyValue(kvmap=kvmap))