On the appointment of the module can be removed from the name. About
HandlerSocket speak a lot and in different languages (mainly in Japanese, English and lately a little in Russian).
The NGX_HTTP_HANDLERSOCKET_JSON_MODULE module accesses MySQL data via the HandlerSocket protocol and sends the data in JSON format. AJAX application.
SourcesAbout configuration, features and limitations can be found below.
Installation
Installation is standard, configuration with the option --add-module:
./configure --add-module=/full/path/to/dir/nginx_http_handlersocket_json_module
Further
make & sudo make install;
Configuration
The configuration is defined in the context of a locale. Example below:
location ~ / json / ( . + ) / $ {
hs_json ;
')
hs_json_host 127 . 0 0 1 ;
hs_json_port 9998 ;
hs_json_db test ;
hs_json_table hs_test ;
hs_json_index code ; # PRIMARY default
hs_json_fields keyid , value , code ;
hs_json_op "=" ; # = default
hs_json_limit 10 ; # default 10
set $ hs_request $ 1 ;
}
In details:
hs_json; - activates the module
Connection parameters (host and port are localhost: 9998 by default, so you can omit it, but you must specify the database name):
hs_json_host 127.0.0.1;
hs_json_port 9998;
hs_json_db test;
Data table and list of selected fields (all parameters are required):
hs_json_table hs_test;
hs_json_fields keyid, value, code;
The index to be sampled:
hs_json_index code;
In the absence of this option, the PRIMARY index is used.
An operation is a condition for retrieving data.
hs_json_op "="; # = default
The following operations are possible: =, <, <=,>,> =
By default, if there is no directive, the operation is "equal"
Restriction on data output:
hs_json_limit 10;
In the absence of directive 10.
The condition for the choice of data is carried out through the $ hs_request variable. Data can be assigned as part of the url:
location
~ / json
/ ( . + ) / $
{set
$ hs_request $ 1 ;}As a variable GET or COOKIES:
location ~ /json {
set $hs_request $get_id;
}
EXAMPLE:
Let it be necessary to choose cities by the first few letters. The list is limited to 10 positions. Cities are selected from the table:
CREATE TABLE city
{name VARCHAR
( 45 ) ,id int
,PRIMARY ( id
) ,KEY `name` ( ` name` ) ,}If you use the following part of the config:
location ~ /city/(.+)/${
..... //
hs_json_index name,
hs_json_fields name;
hs_json_op ">=";
set $hs_request $1;
}
it will be similar to the following query:
SELECT * FROM cities
WHERE city_name
> = '$ hs_request' LIMIT 10The request will be taken from the last part of the URL. For example, for the request: http: // myserver.com/city/san/ a data set will be generated:
[{"name":"San Amaro"},{"name":"San Andreas"},{"name":"San Andrs"} ... ]
Errors
- 500 - Incorrect configuration, protocol implementation error or HS response error
- 503 - no connection with HS or I / O error
If the key is not found, an empty response is given: {[]}, a 404 error is not generated.
Restrictions
- The size of the output buffer should be no more than 1K (1024), regulated by #define BUFF_SIZE. For my tasks no longer needed.
- You can use only a simple index (sampling data by only one criterion)
- until Russian letters are implemented (UTF-8), it will be eliminated soon
About all bugs in bug reports, features and wishes in a personal or comments