lua-rds-parser icon indicating copy to clipboard operation
lua-rds-parser copied to clipboard

is possible to merge two rds result from ngx_postgres or ngx_drizzle

Open lloydzhou opened this issue 11 years ago • 8 comments

is possible to merge two rds result from ngx_postgres or ngx_drizzle?

when i using ngx_drizzle and rds_json to get data from mysql. in one request i want to get one record form user, and get many record from post. i mast parse the two result in to Lua, and merge them.

so i think there should be another easy way to merge the two result.

lloydzhou avatar Apr 23 '14 07:04 lloydzhou

@lloydzhou It is recommended to use Lua to merge RDS resultsets in NGINX.

agentzh avatar Apr 23 '14 18:04 agentzh

@agentzh i have see https://github.com/openresty/replace-filter-nginx-module on you page. may be can using this module to merge the RDS resultsets. may be the performance is better than using lua_rds_parser.

lloydzhou avatar May 12 '14 03:05 lloydzhou

@lloydzhou I'd be surprised if you can manage to do that :)

agentzh avatar May 12 '14 03:05 agentzh

i known the RDS resultsets is banary format, but using rds_json command the results will be translate in json format.

maybe we can just using the ngx_http_ssi_module to merge it:

/comment/533c088348d5b95ac0c34d05
{
    "id": "533c088348d5b95ac0c34d05",
    "content": "test comment content.",
    "atime": 1397385000,
    "user": <!--# include virtual="/user/535a61d09fd71a20d3012d29" -->
}
/user/535a61d09fd71a20d3012d29
{
    "name": "test name",
    "email": "[email protected]",
    "avatar": "/avatar/535667729fd71a573b364cba"
}

lloydzhou avatar May 12 '14 04:05 lloydzhou

Hi @agentzh

I have implemented this feature by add one command to "ngx_rds_json" module. just config this command by 3 params( key, prefix, property).
it can create new "property" valued by a SSI url, which based on the "prefix" when the col name equal "key".
you can see the commit on the fork project of "rds-json-nginx-module" (https://github.com/lloydzhou/rds-json-nginx-module/commit/a9886599952d7f80810af61d717693748e36d26d#commitcomment-6309218)

lloydzhou avatar May 13 '14 18:05 lloydzhou

@lloydzhou I'm afraid it is not quite intuitive and I don't like this route much. I still believe ngx_lua is the right way for such more complicated requirements.

agentzh avatar May 13 '14 18:05 agentzh

@agentzh 其实我心里面也比较认同你说的使用ngx_lua的方案。 或许是对lua这个新语言稍微有点抵触的原因吧,所以才会想尽办法的去找一个自己觉得更简洁(可能在别人看来不是这样),自己觉得使用更方便的方法。。。 对非专业程序员来说,写配置文件应该比写LUA程序代码要简单些。

lloydzhou avatar May 13 '14 18:05 lloydzhou

@lloydzhou Lua was created in 1990s, which is not a new language for its own right. And it might be a new language to you, but it is a very small language and I learned it after I started hacking on the ngx_lua module actually ;) Just check out the following manual: http://www.lua.org/manual/5.1/manual.html And you should be good :)

Back in the year 2009, I was also taking a similar route by extending the nginx.conf scripting possibilities but I quickly abandoned this route because it was proven to be a dead end for really complicated things (and the real world business requirements always tend to grow the complexity exponentially anyway).

agentzh avatar May 13 '14 18:05 agentzh