Skip to content

Commit 59f540c

Browse files
author
DIDAR
committed
Fix json output
1 parent 9da00ba commit 59f540c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/server.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ def index():
2828
print ('Using the following SQL Server version:')
2929
#tsql = "SELECT @@version;"
3030
tsql = "SELECT * FROM dbo.Customers"
31-
df = pd.read_sql(tsql, cnxn)
3231

33-
with cursor.execute(tsql):
34-
row = cursor.fetchone()
35-
response = make_response(str(row), 200)
36-
response.headers["Content-Type"] = "application/json"
37-
# ! TODO FORMAT DATA
38-
return jsonify({"Name": str(df.head) + ' ' + str(row[1])})
32+
# ! TO DO. Use Dataframe
33+
df = pd.read_sql(tsql, cnxn)
3934

35+
result = cursor.execute(tsql)
36+
items = []
37+
for row in result:
38+
items.append({ 'ID': row[0], 'Name': row[1], 'Contact': row[2], 'Title': row[3], 'Address': row[4]})
39+
return jsonify({'cols': str(df.columns), 'items': items})

0 commit comments

Comments
 (0)