Python connect to database and select table in json format
In django project, I connected to databse and wrote "select * from table" to display result in json format, I used for cycle for this, it is working ok, but when there are millions or over millions rows, get request is taking long time and eventually it is stopping without result. Is there any alternative way to proccess this code without using for cycle, since for cycle takes very long time if there are bulk of rows in select query I did all proccesses in urls.py in django project
urls.py
from django.urls import path
from hdbcli import dbapi
from django.http import HttpResponse, JsonResponse
import json
def get_all_users(request):
conn = dbapi.connect(address="localhost", port="xxx", user="xxxx", password="xxxx")
cursor = conn.cursor()
cursor.execute("select bname, name_text, function, department from user_addrs")
objs = cursor.fetchall()
json_data = []
for obj in objs:
json_data.append({
"login" : obj[0],
"full_name" : obj[1],
"function" : obj[2],
"department" : obj[3]
})
return JsonResponse(json_data, safe=False)
urlpatterns = [
path('test/', get_all_users),
]
in browser, result is like this

can anyone help me please to solve this problem, I need a code that returns json response faster even if there bulk of rows in select query
thanks
