{"id":13635995,"url":"https://github.com/openresty/lua-rds-parser","last_synced_at":"2025-04-19T04:31:50.891Z","repository":{"id":48854142,"uuid":"2295372","full_name":"openresty/lua-rds-parser","owner":"openresty","description":"Resty DBD Stream (RDS) parser for Lua written in C","archived":false,"fork":false,"pushed_at":"2023-11-23T12:02:44.000Z","size":28,"stargazers_count":19,"open_issues_count":1,"forks_count":11,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-02-13T20:32:45.999Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openresty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2011-08-30T14:49:37.000Z","updated_at":"2023-09-08T16:30:23.000Z","dependencies_parsed_at":"2024-01-06T22:30:17.184Z","dependency_job_id":"f1d72fec-f57b-41f8-837a-f5a68db04d8e","html_url":"https://github.com/openresty/lua-rds-parser","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-rds-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-rds-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-rds-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-rds-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openresty","download_url":"https://codeload.github.com/openresty/lua-rds-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249606380,"owners_count":21298851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T00:00:55.138Z","updated_at":"2025-04-19T04:31:50.671Z","avatar_url":"https://github.com/openresty.png","language":"C","funding_links":[],"categories":["Libraries","Third Modules","Rust Modules"],"sub_categories":["C Modules","Lua Modules"],"readme":"Name\n====\n\nlua-rds-parser - Resty-DBD-Stream (RDS) parser for Lua written in C\n\nStatus\n======\n\nThis module is production ready.\n\nSynopsis\n========\n\n```lua\nlocal parser = require \"rds.parser\"\n\nlocal res, err = parser.parse(rds)\n\nif res == nil then\n    error(\"failed to parse: \" .. err)\nend\n\nprint(res.errcode)\nprint(res.errstr)\nprint(res.insert_id)\nprint(res.affected_rows)\n\nlocal rows = res.resultset\nif rows then\n    for i, row in ipairs(rows) do\n        for col, val in pairs(row) do\n            if val ~= parser.null then\n                print(col .. \": \" .. val)\n            end\n        end\n    end\nend\n```\n\nDescription\n===========\n\nThis Lua library can be used to parse the Resty-DBD-Stream formatted data\ngenerated by [ngx_drizzle](https://github.com/openresty/drizzle-nginx-module#readme)\nand [ngx_postgres](https://github.com/FRiCKLE/ngx_postgres/) into Lua\ndata structures. In the past, we have to use JSON as the intermediate data\nformat which is quite inefficient in terms of both memory and CPU time.\n\nTo maximize speed and minimize memory footprint, this library is implemented\nin pure C.\n\nNull values in RDS are turned into the light user data `parser.null` (or `ngx.null`)\nwhere \"parser\" is the module object returned by Lua's \"require\".\n\nJSON Serialization\n==================\n\nIf you want to serialize the parsed result into JSON, please\nuse the [lua-cjson library](http://www.kyne.com.au/~mark/software/lua-cjson.php)\ninstead of lua-yajl, because lua-cjson is faster than lua-yajl\nin many common cases, and more importantly,\n\n```lua\nparser.null == cjson.null ~= yajl.null\n```\n\nUsing with HttpDrizzleModule\n============================\n\nTo use with `ngx_drizzle`, here is a small example:\n\n```nginx\nupstream backend {\n    drizzle_server 127.0.0.1:3306 protocol=mysql\n                   dbname=ngx_test user=ngx_test password=ngx_test;\n    drizzle_keepalive max=10 overflow=ignore mode=single;\n}\n\nserver {\n    ...\n\n    location /mysql {\n       drizzle_query $echo_request_body;\n       drizzle_pass backend;\n    }\n\n    location /api {\n       content_by_lua '\n           local sql = \"select * from cats\"\n           local resp = ngx.location.capture(\"/mysql\", {\n               method = ngx.HTTP_POST, body = sql\n           })\n           if resp.status ~= ngx.HTTP_OK or not resp.body then\n               error(\"failed to query mysql\")\n           end\n\n           local parser = require \"rds.parser\"\n           local res, err = parser.parse(resp.body)\n           if res == nil then\n               error(\"failed to parse RDS: \" .. err)\n           end\n\n           local rows = res.resultset\n           if not rows or #rows == 0 then\n               ngx.say(\"empty resultset\")\n               ngx.exit(0)\n           end\n\n           for i, row in ipairs(rows) do\n               ngx.print(\"row \", i, \": \")\n               for col, val in pairs(row) do\n                   if val ~= parser.null then\n                       ngx.print(col, \"=\", val, \" \")\n                   else\n                       ngx.print(col, \"=null \")\n                   end\n               end\n               ngx.say()\n           end\n       ';\n    }\n}\n```\n\nOn my machine, GET /api will yield\n\n\n```\nrow 1: id=2 name=null\nrow 2: id=3 name=bob\n```\n\nof course, the actual output depends on the structure and contents of the\n\"cats\" table in the mysql database.\n\nYou can use this Lua library with the ngx_postgres module in a similar way.\n\nInstallation\n============\n\nBuild requirements\n\n* Lua (http://www.lua.org/),\n* or LuaJIT (http://www.luajit.org/)\n\nGnu make and gcc is required to build this module.\n\nLinux/BSD/Solaris\n----------------\n\n```bash\ngmake CC=gcc\ngmake install CC=gcc\n```\n\nMac OS X\n--------\n\n```bash\nmake LDFLAGS='-bundle -undefined dynamic_lookup' CC=gcc\nmake install\n```\n\nIf your Lua or LuaJIT is not installed into the system, specify its\ninclude directory like this:\n\n```bash\nmake LUA_INCLUDE_DIR=/opt/luajit/include/luajit-2.0\n```\n\nYou can specify a custom path for the installation target:\n\n```bash\nmake install LUA_LIB_DIR=/opt/lualib\n```\n\nThe `DESTDIR` variable is also supported, to ease RPM packaging.\n\nTODO\n====\n\n* add support for option \"compact\" to generate a compact\nLua table for the \"resultset\" field.\n\nKnown Issues\n============\n\n* The endianness flag in RDS is not supported yet in this library,\nand it will assume it's of the host's endian. So do not\ntry parsing the RDS stream that is generated by another\nmachine of a different endian.\n\nAuthor\n======\n\nYichun \"agentzh\" Zhang \u003cagentzh@gmail.com\u003e, CloudFlare Inc.\n\nCopyright \u0026 License\n===================\n\nThis module is licenced under the BSD license.\n\nCopyright (C) 2011-2016, Zhang \"agentzh\" Yichun (章亦春) \u003cagentzh@gmail.com\u003e.\n\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions\nare met:\n\n* Redistributions of source code must retain the above copyright\nnotice, this list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright\nnotice, this list of conditions and the following disclaimer in the\ndocumentation and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nHOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\nTO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\nPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\nNEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenresty%2Flua-rds-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenresty%2Flua-rds-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenresty%2Flua-rds-parser/lists"}