def get_query(cls, chart_id): Logger.info("get: chart_id={chart_id}".format(chart_id=chart_id)) row = cls.get(chart_id, ['query']) if row: return row['query'] else: return None
def get(cls, chart_id, columns=None): Logger.info("get: chart_id={chart_id}, columns={columns}".format( chart_id=chart_id, columns=columns)) if not columns: columns = ['*'] if not isinstance(columns, list): columns = [columns] connection = cls.__get_db() try: with connection.cursor() as cursor: sql = "SELECT {0} FROM charts WHERE id=%s".format( ','.join(columns)) cursor.execute(sql, (chart_id, )) return cursor.fetchone() finally: connection.close()