-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpinky_mydb.lua
41 lines (35 loc) · 1 KB
/
pinky_mydb.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
local p = require 'pinky'
local luasql = require "luasql.mysql"
--local yaml = require "lyaml"
local function pinky_main(uri,ps)
-- This function is the entry point.
-- /pinky/mysql/check/host
--
-- local config = read_mmtop_config()
ps.data = mysql_query("localhost","mmtop","lalala","test","show global status")
return ps
end
function mysql_connect(host,user,password,db)
env = assert (luasql.mysql())
con = assert (env:connect("test",user,password,host))
return con
end
function mysql_query(host,user,password,db,query)
-- return a table of the results
out = {}
con = mysql_connect(host,user,password,"test")
cur = con:execute(query)
row = cur:fetch ({}, "a")
while row do
table.insert(out,row)
-- reusing the table of results
row = cur:fetch ({}, "a")
end
cur:close()
con:close()
return out
end
-- function read_mmtop_config()
-- return yaml.load(p.read_file("/data/pinky-server/.mmtop_config"))
-- end
return { pinky_main = pinky_main }