On 17 Oct 2013 02:21, "Roberto Ostinelli" <rob...@ostinelli.net> wrote:
>
> Thank you Jiale,
>
> this is indeed interesting. I've seen what you did there, but before using a nginx hack like this, isn't there another direct way to access it somehow? The reason I'm asking is that I want to be able todo more, including running a console against resty.mysql.
>
I was thinking of looking at this at some point. It would mean implementing enough of ngx.* to run these libraries standalone. But the solution above looks pretty workable.
Justin
> r.
>
>
>
> On Oct 16, 2013, at 9:15 PM, Jiale Zhi <vip...@gmail.com> wrote:
>
>> Hi Roberto,
>>
>> I have a tool which can satisfy your needs. It is called luangx. It acts as a lua interpreter, but internally uses ngx_lua to do all the things. So you can use ngx.* calls and variables in your lua code and test your code.
>>
>> You can get this tool from https://github.com/calio/luangx.
>>
>> For example you have a lua file called sql.lua:
>>
>>> local mysql = require "resty.mysql"
>>> local db, err = mysql:new()
>>> if not db then
>>> ngx.say("failed to instantiate mysql: ", err)
>>> return
>>> end
>>>
>>> db:set_timeout(1000) -- 1 sec
>>>
>>> local ok, err, errno, sqlstate = db:connect{
>>> host = "127.0.0.1",
>>> port = 3306,
>>> database = "test",
>>> user = "calio",
>>> password = "",
>>> max_packet_size = 1024 * 1024 }
>>>
>>> if not ok then
>>> ngx.say("failed to connect: ", err, ": ", errno, " ", sqlstate)
>>> return
>>> end
>>>
>>> ngx.say("connected to mysql.")
>>>
>>> local res, err, errno, sqlstate =
>>> db:query("select * from t1")
>>> if not res then
>>> ngx.say("bad result: ", err, ": ", errno, ": ", sqlstate, ".")
>>> return
>>> end
>>>
>>> ngx.say(string.format("Got %d rows", #res))
>>
>>
>> You can execute this lua script from command line using, make sure luangx and nginx could be found in your $PATH:
>>>
>>> $ luangx sql.lua
>>>
>> Then you would get a few outputs with nginx error in stderr and lua script output in stdout. This tool still lacks a lot of features, so patches are welcome.
>>
>>
>>
>> On Oct 16, 2013, at 5:17 PM, Roberto Ostinelli <osti...@gmail.com> wrote:
>>
>>> I'd love to be able to perform SQL task that can be run from command-line, and would love to avoid having another SQL driver in.
>>>
>>> Is there a way to run the embedded lua and use the resty.mysql from there?
>>>
>>> Thank you :)
>>>
>>> r..