mysqlproxy.lua
1.18 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
local skynet = require "skynet"
require "utils.init"
local mysqld_count = tonumber(skynet.getenv("thread"))
local mysqld
skynet.init(function()
local idx = math.randomInt(1, mysqld_count)
mysqld = skynet.localname(".mysql" .. idx)
end)
local table_insert = table.insert
local mysqlproxy = {}
setmetatable(mysqlproxy, { __index = function(t, k)
local cmd = string.upper(k)
local f = function (self, ...)
if k == "query" then
--print(...)
end
local ok, result = pcall(skynet.call, mysqld, "lua", cmd, ...)
if not ok then
skynet.error(cmd, ..., "\n", debug.traceback(coroutine.running(), nil))
return
end
return result
end
t[k] = f
return f
end})
function mysqlproxy:insertEmail(params)
local pms = {
key = string.format("%s", 0),
roleId = params.roleId,
emailId = params.emailId,
createtime = params.createtime or skynet.timex(),
contentPms = params.contentPms or {},
rewardPms = params.rewardPms or {},
title = params.title or "",
stitle = params.stitle or "",
content = params.content or "",
attachments = params.attachments or "",
}
local email = require("models.Email").new(pms)
email:create()
return true
end
return mysqlproxy