Skip to content

Commit

Permalink
Add "postgres_rewrite" directive.
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrSikora committed Jun 23, 2010
1 parent 12c2710 commit d2a5392
Show file tree
Hide file tree
Showing 16 changed files with 957 additions and 102 deletions.
17 changes: 15 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ CONFIGURATION DIRECTIVES:
default: none


postgres_query [method .. method] query (context: http, server, location)
-------------------------------------------------------------------------
postgres_query [methods] query (context: http, server, location)
----------------------------------------------------------------
Set query string (it can include variables). When methods are specified
then query is used only for them, otherwise it's used for all methods.

Expand All @@ -47,6 +47,19 @@ CONFIGURATION DIRECTIVES:
default: none


postgres_rewrite [methods] condition status (context: http, server, location)
-----------------------------------------------------------------------------
Rewrite response status code when given condition is met (first one wins!):
- no_changes - no rows were affected by SQL query (by design this applies only to
INSERT, UPDATE, DELETE, MOVE, FETCH and COPY SQL queries),
- changes - at least one row was affected by SQL query (by design this applies
only to INSERT, UPDATE, DELETE, MOVE, FETCH and COPY SQL queries),
- no_rows - no rows were returned in the result-set,
- rows - at least one row was returned in the result-set.

default: none


postgres_output none|value|row|rds [row] [column] (context: http, server, location)
-----------------------------------------------------------------------------------
Set output format:
Expand Down
4 changes: 2 additions & 2 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fi
ngx_addon_name=ngx_postgres_module

HTTP_MODULES="$HTTP_MODULES ngx_postgres_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_postgres_handler.c $ngx_addon_dir/src/ngx_postgres_keepalive.c $ngx_addon_dir/src/ngx_postgres_module.c $ngx_addon_dir/src/ngx_postgres_output.c $ngx_addon_dir/src/ngx_postgres_processor.c $ngx_addon_dir/src/ngx_postgres_upstream.c $ngx_addon_dir/src/ngx_postgres_util.c $ngx_addon_dir/src/ngx_postgres_variable.c"
NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ngx_postgres_handler.h $ngx_addon_dir/src/ngx_postgres_keepalive.h $ngx_addon_dir/src/ngx_postgres_module.h $ngx_addon_dir/src/ngx_postgres_output.h $ngx_addon_dir/src/ngx_postgres_processor.h $ngx_addon_dir/src/ngx_postgres_upstream.h $ngx_addon_dir/src/ngx_postgres_util.h $ngx_addon_dir/src/ngx_postgres_variable.h $ngx_addon_dir/src/ngx_postgres_ddebug.h $ngx_addon_dir/src/resty_dbd_stream.h"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_postgres_handler.c $ngx_addon_dir/src/ngx_postgres_keepalive.c $ngx_addon_dir/src/ngx_postgres_module.c $ngx_addon_dir/src/ngx_postgres_output.c $ngx_addon_dir/src/ngx_postgres_processor.c $ngx_addon_dir/src/ngx_postgres_rewrite.c $ngx_addon_dir/src/ngx_postgres_upstream.c $ngx_addon_dir/src/ngx_postgres_util.c $ngx_addon_dir/src/ngx_postgres_variable.c"
NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ngx_postgres_handler.h $ngx_addon_dir/src/ngx_postgres_keepalive.h $ngx_addon_dir/src/ngx_postgres_module.h $ngx_addon_dir/src/ngx_postgres_output.h $ngx_addon_dir/src/ngx_postgres_processor.h $ngx_addon_dir/src/ngx_postgres_rewrite.h $ngx_addon_dir/src/ngx_postgres_upstream.h $ngx_addon_dir/src/ngx_postgres_util.h $ngx_addon_dir/src/ngx_postgres_variable.h $ngx_addon_dir/src/ngx_postgres_ddebug.h $ngx_addon_dir/src/resty_dbd_stream.h"

have=NGX_POSTGRES_MODULE . auto/have
5 changes: 3 additions & 2 deletions src/ngx_postgres_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ ngx_postgres_handler(ngx_http_request_t *r)

pglcf = ngx_http_get_module_loc_conf(r, ngx_postgres_module);

if ((pglcf->default_query == NULL) && !(pglcf->methods_set & r->method)) {
if (pglcf->methods_set != 0) {
if ((pglcf->query.def == NULL) && !(pglcf->query.methods_set & r->method)) {
if (pglcf->query.methods_set != 0) {
dd("returning NGX_HTTP_NOT_ALLOWED");
return NGX_HTTP_NOT_ALLOWED;
}
Expand Down Expand Up @@ -155,6 +155,7 @@ ngx_postgres_handler(ngx_http_request_t *r)
* pgctx->response = NULL
* pgctx->var_query = { 0, NULL }
* pgctx->variables = NULL
* pgctx->status = 0
*/

pgctx->var_cols = NGX_ERROR;
Expand Down
Loading

0 comments on commit d2a5392

Please sign in to comment.