diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-12-02 13:22:53 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-12-02 13:22:53 +0000 |
commit | fe940c7d3d9d72f0196b9cd847dd0160603dcbe9 (patch) | |
tree | 872613ef46ccea45bceb9dde82c987dfd973e44d /lualib/lua_clickhouse.lua | |
parent | 9508d87e3ceffeb21795eb1356229f48648182bf (diff) | |
download | rspamd-fe940c7d3d9d72f0196b9cd847dd0160603dcbe9.tar.gz rspamd-fe940c7d3d9d72f0196b9cd847dd0160603dcbe9.zip |
[Feature] Support ClickHouse database
Issue: #2655
Diffstat (limited to 'lualib/lua_clickhouse.lua')
-rw-r--r-- | lualib/lua_clickhouse.lua | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lualib/lua_clickhouse.lua b/lualib/lua_clickhouse.lua index e14518ca6..bdb096d04 100644 --- a/lualib/lua_clickhouse.lua +++ b/lualib/lua_clickhouse.lua @@ -222,7 +222,9 @@ exports.select = function (upstream, settings, params, query, ok_cb, fail_cb) connect_prefix = 'https://' end local ip_addr = upstream:get_addr():to_string(true) - http_params.url = connect_prefix .. ip_addr .. '/?default_format=JSONEachRow' + local database = params.database or 'default' + http_params.url = string.format('%s%s/?database=%s&default_format=JSONEachRow', + connect_prefix, ip_addr, escape_spaces(database)) end return rspamd_http.request(http_params) @@ -271,7 +273,9 @@ exports.select_sync = function (upstream, settings, params, query, ok_cb, fail_c connect_prefix = 'https://' end local ip_addr = upstream:get_addr():to_string(true) - http_params.url = connect_prefix .. ip_addr .. '/?default_format=JSONEachRow' + local database = params.database or 'default' + http_params.url = string.format('%s%s/?database=%s&default_format=JSONEachRow', + connect_prefix, ip_addr, escape_spaces(database)) end local err, response = rspamd_http.request(http_params) @@ -333,9 +337,11 @@ exports.insert = function (upstream, settings, params, query, rows, connect_prefix = 'https://' end local ip_addr = upstream:get_addr():to_string(true) - http_params.url = string.format('%s%s/?query=%s%%20FORMAT%%20TabSeparated', + local database = params.database or 'default' + http_params.url = string.format('%s%s/?database=%s&query=%s%%20FORMAT%%20TabSeparated', connect_prefix, ip_addr, + escape_spaces(database), escape_spaces(query)) end @@ -383,7 +389,9 @@ exports.generic = function (upstream, settings, params, query, connect_prefix = 'https://' end local ip_addr = upstream:get_addr():to_string(true) - http_params.url = connect_prefix .. ip_addr .. '/?default_format=JSONEachRow' + local database = params.database or 'default' + http_params.url = string.format('%s%s/?database=%s&default_format=JSONEachRow', + connect_prefix, ip_addr, escape_spaces(database)) end return rspamd_http.request(http_params) @@ -426,7 +434,9 @@ exports.generic_sync = function (upstream, settings, params, query) connect_prefix = 'https://' end local ip_addr = upstream:get_addr():to_string(true) - http_params.url = connect_prefix .. ip_addr .. '/?default_format=JSONEachRow' + local database = params.database or 'default' + http_params.url = string.format('%s%s/?database=%s&default_format=JSONEachRow', + connect_prefix, ip_addr, escape_spaces(database)) end return rspamd_http.request(http_params) |