Welcome! Log In Create A New Profile

Advanced

rds-json generate json with index key on first level of array

February 25, 2013 02:54AM
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
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

rds-json generate json with index key on first level of array

replay February 25, 2013 02:54AM

Re: rds-json generate json with index key on first level of array

replay February 25, 2013 03:04AM

Re: rds-json generate json with index key on first level of array

smallfish February 25, 2013 03:14AM

Re: rds-json generate json with index key on first level of array

replay February 25, 2013 03:58AM

Re: rds-json generate json with index key on first level of array

agentzh February 25, 2013 03:04PM

Re: rds-json generate json with index key on first level of array

replay February 26, 2013 11:58PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 259
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready