I am using SQLAlchemy connection.execute(sql) to transform select results to array of maps. Have following code
def __sql_to_data(sql):
result = []
connection = engine.connect()
try:
rows = connection.execute(sql)
for row in rows:
result_row = {}
for col in row.keys():
result_row[str(col)] = str(row[col])
result.append(result_row)
finally:
connection.close()
return result
and e.g.
__sql_to_data(sql_get_scan_candidate)
gives me nice data structure (Of course I am using this for small data sets).
But in order to add parameter to sql I am currently using format e.g.
return __sql_to_data(sql_get_profile.format(user_id))
Question How to modify procedure to make possible something like
return __sql_to_data(sql_get_profile,user_id)
See Question&Answers more detail:os