Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to use the module from content_by_lua_file #34

Open
nbhatti opened this issue Feb 8, 2015 · 3 comments
Open

Possible to use the module from content_by_lua_file #34

nbhatti opened this issue Feb 8, 2015 · 3 comments

Comments

@nbhatti
Copy link

nbhatti commented Feb 8, 2015

I am using currently using content_by_lua_file, so I was thinking if I can use the module from the lua script itself?

@agentzh
Copy link
Contributor

agentzh commented Feb 9, 2015

@nbhatti Sure. You can use the ngx.location.capture to initiate nginx subrequest to a (internal) location configured by ngx_postgres. AFAIK, qunar.com has been using this approach in production for years already :)

@nbhatti
Copy link
Author

nbhatti commented Feb 16, 2015

@agentzh Do you have an example? I want to manage db connection and everything inside the Lua script and not in nginx directives. Currently I am just passing everything to content_by_lua_file and initiate the db connection and complete the script. Is that aso doable with ngx.location.capture?

@agentzh
Copy link
Contributor

agentzh commented Feb 16, 2015

@nbhatti Then you should not use ngx_postgres in the first place. There're some 3rd-party pure Lua PostgreSQL client libraries based on ngx_lua's nonblocking cosocket API, for example,

  1. https://github.com/azurewang/lua-resty-postgres
  2. https://github.com/leafo/pgmoon

They're much more flexible than doing subrequests + ngx_postgres.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants