rds-json generate json with index key on first level of array
Mauro Stettler
mauro.stettler at gmail.com
Mon Feb 25 07:52:38 UTC 2013
Hello Nginx list
I'm using OpenResty with libdrizzle to provide a faster API to query
certain things from my db.
My current config is like this:
location ~* ^/resty/usersTable/userId/([0-9\,]+)$ {
set_unescape_uri $uid $1;
drizzle_query 'select id, nickname, age, age_p, city, plz,
wio_plz, gender from users where id in ($uid)';
drizzle_pass projectdb;
rds_json on;
}
So this works fine and it gives me the expected output.
My problem is that if I query many user IDs i'm only getting a flat array
of arrays without index key. But to improve the processing speed on the
client side, I would like to define that the 'id' field should be the first
level index in the returned array. I am trying to show what I mean:
Current output:
[
{"id":1971,"nickname":"Robby1","age":28,"age_p":42,"city":"Dresden","plz":"","wio_plz":"2,4,5","gender":"m"},
{"id":1972,"nickname":"Robby2","age":29,"age_p":43,"city":"Dresden2","plz":"","wio_plz":"4,5","gender":"f"},
{"id":1973,"nickname":"Robby3","age":30,"age_p":44,"city":"Dresden3","plz":"","wio_plz":"5","gender":"m"},
]
What I want:
[
1971:{"nickname":"Robby1","age":28,"age_p":42,"city":"Dresden","plz":"","wio_plz":"2,4,5","gender":"m"},
1972:{"nickname":"Robby2","age":29,"age_p":43,"city":"Dresden2","plz":"","wio_plz":"4,5","gender":"f"},
1973:{"nickname":"Robby3","age":30,"age_p":44,"city":"Dresden3","plz":"","wio_plz":"5","gender":"m"},
]
Is there some way how I can define a first level index key in rds-json? I
already checked the `rds_json_root` parameter, but this doesn't seem to be
what I'm looking for.
Thanks,
Mauro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20130225/093dc41a/attachment.html>
More information about the nginx
mailing list