I was doing this SQLAlchemy and pyodbc connection, but when I get my data from query it returns a tuple list without key, only value.
For example
[(valueOfObjectsSeparatedByComa), (valueOfObjectsSeparatedByComa), etc..]
This is my code.
from flask import Flask, request
from flask_restful import Resource, Api
import sqlalchemy as sa
from flask_sqlalchemy import SQLAlchemy
import json
from json import dumps
from flask.ext.jsonpify import jsonify
import pyodbc
client = pyodbc.connect('DRIVER={SQLSERVERDRIVER};SERVER=serverName;DATABASE=database;UID=user;PWD=password')
class Users(Resource):
def get(self):
query =("select * from SEC_User")
try:
result = client.execute(query).fetchall()
return jsonify(result)
except Exception as e:
client.close()
raise e
api.add_resource(Users, '/users') # Route_1
When I do a print(result)
I can see the data in tuple format and only the value not the key, for example, instead of "name": "john"
[(john), (james)]
the correct would be [{name: jonh}, {name: james}]
.
What can I do to change the tuple data?