Skip to content
Snippets Groups Projects
Verified Commit baf78aeb authored by Denis Smirnov's avatar Denis Smirnov
Browse files

feat: improve SQL results formatting in Lua

parent 08b0c3f6
No related branches found
No related tags found
1 merge request!1414sbroad import
require('strict').on()
require('sbroad')
require('sbroad.core-router')
local helper = require('sbroad.helper')
local cartridge = require('cartridge')
......@@ -65,7 +66,7 @@ local function trace(query, params, context, id)
return nil, parser_res
end
return parser_res[1]
return helper.format_result(parser_res[1])
end
local function execute(query, params)
......@@ -79,7 +80,7 @@ local function execute(query, params)
return nil, parser_res
end
return parser_res[1]
return helper.format_result(parser_res[1])
end
return {
......
......@@ -6,6 +6,22 @@ local function module_name()
end
end
local function format_result(result)
local formatted = {}
if result['metadata'] ~= nil then
formatted.metadata = setmetatable(result.metadata, { __serialize = nil })
end
if result['rows'] ~= nil then
formatted.rows = setmetatable(result.rows, { __serialize = nil })
end
if result['metadata'] == nil and result['rows'] == nil then
formatted = setmetatable(result, { __serialize = nil })
end
return formatted
end
return {
module_name = module_name,
format_result = format_result,
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment