• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

src/H03-Nov-2017-3,4752,373

t/H03-Nov-2017-4,6323,824

util/H03-Nov-2017-189130

.gitattributesH A D03-Nov-201727 21

.gitignoreH A D03-Nov-2017744 7574

.travis.ymlH A D03-Nov-20173.3 KiB8776

README.mdH A D03-Nov-20179.9 KiB366251

configH A D03-May-2022818 106

valgrind.suppressH A D03-Nov-20176.3 KiB327326

README.md

1Name
2====
3
4ngx_rds_json - an output filter that formats Resty DBD Streams generated by ngx_drizzle and others to JSON
5
6Table of Contents
7=================
8
9* [Name](#name)
10* [Status](#status)
11* [Synopsis](#synopsis)
12* [Description](#description)
13* [Directives](#directives)
14    * [rds_json](#rds_json)
15    * [rds_json_buffer_size](#rds_json_buffer_size)
16    * [rds_json_format](#rds_json_format)
17    * [rds_json_root](#rds_json_root)
18    * [rds_json_success_property](#rds_json_success_property)
19    * [rds_json_user_property](#rds_json_user_property)
20    * [rds_json_errcode_key](#rds_json_errcode_key)
21    * [rds_json_errstr_key](#rds_json_errstr_key)
22    * [rds_json_ret](#rds_json_ret)
23    * [rds_json_content_type](#rds_json_content_type)
24* [Installation](#installation)
25* [Compatibility](#compatibility)
26* [Author](#author)
27* [Copyright & License](#copyright--license)
28* [See Also](#see-also)
29
30Status
31======
32
33This module is considered production ready.
34
35We need your help! If you find this module useful and/or interesting, please consider joining the development!
36Commit bit can be freely delivered at your request ;)
37
38Synopsis
39========
40
41```nginx
42server {
43    location /mysql {
44        drizzle_query 'select * from cats';
45        drizzle_pass my_mysql_upstream;
46
47        rds_json on;
48    }
49
50    location /foo {
51        if ($arg_limit !~ '^\d{2}$') {
52            rds_json_ret 400 'Bad "limit" argument';
53        }
54
55        drizzle_query "select * from dogs limit $arg_limit";
56        drizzle_pass my_mysql_upstream;
57
58        rds_json on;
59    }
60    ...
61}
62```
63
64Description
65===========
66
67This module provides an output filter that can format the RDS outputs
68generated by [ngx_drizzle](https://github.com/openresty/drizzle-nginx-module)
69and [ngx_postgres](https://github.com/FRiCKLE/ngx_postgres/) modules to JSON.
70
71[Back to TOC](#table-of-contents)
72
73Directives
74==========
75
76[Back to TOC](#table-of-contents)
77
78rds_json
79--------
80**syntax:** *rds_json on|off*
81
82**default:** *rds_json off*
83
84**context:** *http, server, location, if location*
85
86Enables or disables the output filter of this module.
87
88[Back to TOC](#table-of-contents)
89
90rds_json_buffer_size
91--------------------
92**syntax:** *rds_json_buffer_size   <bytes>*
93
94**default:** *rds_json_buffer_size <page-size>*
95
96**context:** *http, server, location, if location*
97
98Controls the buffer size used by this module. default to the page size (4k/8k).
99The bigger the buffer size, the less streammy the conversion
100will be. But usually increasing the buffer size
101does help reduce CPU time.
102
103[Back to TOC](#table-of-contents)
104
105rds_json_format
106---------------
107**syntax:** *rds_json_format  normal|compact*
108
109**default:** *rds_json_format normal*
110
111**context:** *http, server, location, if location*
112
113Controls the output JSON format. A sample of the default "normal" format
114looks like this
115
116```json
117 [{"id":1,"name":"marry"},{"id":2,"name":"bob"}]
118```
119
120while it looks like below when in the "compact" format
121
122```json
123 [["id","name"],[1,"marry"],[2,"bob"]]
124```
125
126that is, the first row holds the column name list.
127
128[Back to TOC](#table-of-contents)
129
130rds_json_root
131-------------
132**syntax:** *rds_json_root <key>*
133
134**default:** *no*
135
136**context:** *http, server, location, if location*
137
138Specifies the "root" key for data rows (if any). For example,
139
140```nginx
141 rds_json on;
142 rds_json_root rows;
143```
144
145will return JSON output like this:
146
147```json
148 {"rows":[{"id":2,"name":null},{"id":3,"name":"bob"}]}
149```
150
151if `rds_json_format compact` is also specified, then the
152output will look like this:
153
154```json
155 {"rows":[["id","name"],[2,null],[3,"bob"]]}
156```
157
158Nginx variables are not supported in the <key> argument of
159this directive.
160
161If this directive is not defined, neither are [rds_json_success_property](#rds_json_success_property),
162nor [rds_json_user_property](#rds_json_user_property), the JSON output for select queries will
163just be an array at the top level.
164
165When either [rds_json_success_property](#rds_json_success_property) or [rds_json_user_property](#rds_json_user_property) are specified,
166this directive takes a default argument of "data".
167
168[Back to TOC](#table-of-contents)
169
170rds_json_success_property
171-------------------------
172**syntax:** *rds_json_success_property &lt;key&gt;*
173
174**default:** *no*
175
176**context:** *http, server, location, if location*
177
178Specifies the top-level object property name used in the JSON output
179for indicating success or false of the query.
180
181[Back to TOC](#table-of-contents)
182
183rds_json_user_property
184-----------------------
185**syntax:** *rds_json_user_property &lt;key&gt; &lt;value&gt;*
186
187**default:** *no*
188
189**context:** *http, server, location, if location*
190
191Specifies additonal user properties for the top-level object
192of the JSON output.
193
194Multiple instances of this directives are allowed in a single scope.
195
196Nginx variables are supported in the `value` argument.
197
198Both of the `key` and `value` arguments will be automatically
199quoted according to JSON strings' notation.
200
201[Back to TOC](#table-of-contents)
202
203rds_json_errcode_key
204---------------------
205**syntax:** *rds_json_errcode_key &lt;key&gt;*
206
207**default:** *rds_json_errcode_key errcode*
208
209**context:** *http, server, location, if location*
210
211Specifies the errcode key name used in the JSON output.
212
213[Back to TOC](#table-of-contents)
214
215rds_json_errstr_key
216-------------------
217**syntax:** *rds_json_errstr_key &lt;key&gt;*
218
219**default:** *rds_json_errstr_key errstr*
220
221**context:** *http, server, location, if location*
222
223Specifies the errstr key name used in the JSON output.
224
225[Back to TOC](#table-of-contents)
226
227rds_json_ret
228------------
229**syntax:** *rds_json_ret &lt;error-code&gt; &lt;descrption&gt;*
230
231**default:** *no*
232
233**context:** *location, if location*
234
235This directive enables a content handler that simply emits
236an response body like this:
237
238```json
239 {"errcode":<error-code>,"errstr":"<description>"}
240```
241
242while the `<description>` string will be properly quoted as
243a JSON string.
244
245[Back to TOC](#table-of-contents)
246
247rds_json_content_type
248---------------------
249**syntax:** *rds_json_content_type &lt;mime-type&gt;*
250
251**default:** *rds_json_content_type application/json*
252
253**context:** *http, server, location, if location*
254
255Controls the `Content-Type` header of the response generated by
256this module's output filter.
257
258[Back to TOC](#table-of-contents)
259
260Installation
261============
262
263You're recommended to install this module (as well as the Nginx core and many other goodies) via the [OpenResty bundle](http://openresty.org). See [the detailed instructions](http://openresty.org/#Installation) for downloading and installing OpenResty into your system. This is the easiest and most safe way to set things up.
264
265Alternatively, you can install this module manually with the Nginx source:
266
267Grab the nginx source code from [nginx.org](http://nginx.org/), for example,
268the version 1.13.6 (see [nginx compatibility](#compatibility)), and then build the source with this module:
269
270```bash
271
272 $ wget 'http://nginx.org/download/nginx-1.13.6.tar.gz'
273 $ tar -xzvf nginx-1.13.6.tar.gz
274 $ cd nginx-1.13.6/
275
276 # Here we assume you would install you nginx under /opt/nginx/.
277 $ ./configure --prefix=/opt/nginx \
278     --add-module=/path/to/rds-json-nginx-module
279
280 $ make -j2
281 $ make install
282```
283
284Download the latest version of the release tarball of this module from [rds-json-nginx-module file list](https://github.com/openresty/rds-json-nginx-module/tags).
285
286Also, this module is included and enabled by default in the [OpenResty bundle](http://openresty.org).
287
288[Back to TOC](#table-of-contents)
289
290Compatibility
291=============
292The following versions of Nginx should work with this module:
293
294* **1.13.x** (last tested: 1.13.6)
295* **1.12.x**
296* **1.11.x** (last tested: 1.11.2)
297* **1.10.x**
298* **1.9.x** (last tested: 1.9.7)
299* **1.8.x**
300* **1.7.x** (last tested: 1.7.10)
301* **1.6.x**
302* **1.5.x** (last tested: 1.5.12)
303* **1.4.x** (last tested: 1.4.4)
304* **1.2.x** (last tested: 1.2.9)
305* **1.1.x** (last tested: 1.1.5)
306* **1.0.x** (last tested: 1.0.9)
307* **0.9.x** (last tested: 0.9.4)
308* **0.8.x** (last tested: 0.8.55)
309* **0.7.x >= 0.7.46** (last tested: 0.7.68)
310
311Earlier versions of Nginx like 0.6.x and 0.5.x will *not* work.
312
313If you find that any particular version of Nginx above 0.7.44 does not
314work with this module, please consider reporting a bug.
315
316[Back to TOC](#table-of-contents)
317
318Author
319======
320Yichun "agentzh" Zhang (章亦春) *&lt;agentzh@gmail.com&gt;*, OpenResty Inc.
321
322[Back to TOC](#table-of-contents)
323
324Copyright & License
325===================
326
327This module is licenced under the BSD license.
328
329Copyright (C) 2009-2017, Yichun Zhang (agentzh) &lt;agentzh@gmail.com&gt;, OpenResty Inc.
330
331All rights reserved.
332
333Redistribution and use in source and binary forms, with or without
334modification, are permitted provided that the following conditions
335are met:
336
337* Redistributions of source code must retain the above copyright
338notice, this list of conditions and the following disclaimer.
339* Redistributions in binary form must reproduce the above copyright
340notice, this list of conditions and the following disclaimer in the
341documentation and/or other materials provided with the distribution.
342
343THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
344"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
345LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
346A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
347HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
348SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
349TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
350PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
351LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
352NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
353SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
354
355[Back to TOC](#table-of-contents)
356
357See Also
358========
359
360* [ngx_drizzle](https://github.com/openresty/drizzle-nginx-module)
361* [ngx_postgres](https://github.com/FRiCKLE/ngx_postgres/)
362* [ngx_rds_csv](https://github.com/openresty/rds-csv-nginx-module)
363
364[Back to TOC](#table-of-contents)
365
366